FlyDB icon indicating copy to clipboard operation
FlyDB copied to clipboard

Modify the configuration method of the configuration file

Open sjcsjc123 opened this issue 2 years ago • 3 comments

image The configuration method in the figure is relatively common, and it is configured using the method of 'with' and 'parameter name'

sjcsjc123 avatar Aug 31 '23 09:08 sjcsjc123

I've implemented a demo in my forked repository, and I would like to ask if this is the correct way to modify? my forked repository implementation :

package config

type FlyDBOption func(*Options)

func WithDirPath(dirPath string) FlyDBOption {
	return func(o *Options) {
		o.DirPath = dirPath
	}
}

func WithDataFileSize(dataFileSize int64) FlyDBOption {
	return func(o *Options) {
		o.DataFileSize = dataFileSize
	}
}

func WithSyncWrite(syncWrite bool) FlyDBOption {
	return func(o *Options) {
		o.SyncWrite = syncWrite
	}
}

func WithIndexType(indexType IndexerType) FlyDBOption {
	return func(o *Options) {
		o.IndexType = indexType
	}
}

func WithFIOType(fioType FIOType) FlyDBOption {
	return func(o *Options) {
		o.FIOType = fioType
	}
}

func NewOptions(opts ...FlyDBOption) *Options {
	newOptions := DefaultOptions
	for _, opt := range opts {
		opt(&newOptions)
	}

	return &newOptions
}

example :

func main() {
	db, err := flydb.NewFlyDB(config.WithDirPath("/tmp/flydb"))
	if err != nil {
		panic(err)
	}

	err = db.Put([]byte("name"), []byte("flydb-example"))
	if err != nil {
		panic(err)
	}

	val, err := db.Get([]byte("name"))
	if err != nil {
		panic(err)
	}

	fmt.Println("name value => ", string(val))

	err = db.Delete([]byte("name"))
	if err != nil {
		panic(err)
	}

}

I would like to know if adjustments are needed for NewColumn and engine.NewDB? However, modifying these two methods would require changing a lot of code. If NewFlyDB is to be changed, then the previous versions will not be compatible.

liooooo29 avatar Jul 26 '24 03:07 liooooo29

Do I need to submit a PR to provide my code?

liooooo29 avatar Aug 05 '24 15:08 liooooo29

Large amounts of code modifications will not be considered until FlyDB 2.0 is released

qishenonly avatar Aug 06 '24 02:08 qishenonly