sqljsondb

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 9 Imported by: 0

README

sqljsondb GoDoc

a key-value json document DB but use MySQL as storage

Usage

db := sqljsondb.New("user:pass@tcp(127.0.0.1:3306)/dbname", "")


db.Write("people", "1", "Alice")
db.Write("people", "2", "Bob")

var name string
db.Read("people", "2", name)
fmt.Println(name)     /// Bob

fmt.Println(db.Keys("people"))    /// {"1", "2"}


db.WriteIgnore("people", "2", "Bob")   /// Does nothing because document "2" is already "Bob"
db.WriteIgnore("people", "2", "Evil")  /// Document "2" updated to "Evil"

For more usage check doc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepEqualRaw

func DeepEqualRaw(a, b []byte) bool

/ Compare if two JSON string is equal in object level.

Types

type Driver

type Driver struct {
	DSN         string
	DBEngine    *gorose.Engin
	TablePrefix string

	ExistsCol sync.Map

	AfterUpdateFunc func(col string, key string, i interface{})
	// contains filtered or unexported fields
}

func New

func New(dsn string, prefix string) (*Driver, error)

/ dsn is the DSN connection string. / prefix is the table prefix.

func (*Driver) DB

func (t *Driver) DB() gorose.IOrm

func (*Driver) Keys

func (t *Driver) Keys(col string) ([]string, error)

/ Get all keys of a collection

func (*Driver) KeysWhereSQL

func (t *Driver) KeysWhereSQL(col string, WhereSQL string) ([]string, error)

/ Get all keys of a collection with customize SQL WHERE condition. / Warning: You have to make sure there is no SQL injection vulnerability in WhereSQL string.

func (*Driver) Read

func (t *Driver) Read(col string, key string, v interface{}) error

/ Read the object and unmarshal it to v

func (*Driver) ReadRaw

func (t *Driver) ReadRaw(col string, key string) ([]byte, error)

/ Read the raw content of the object.

func (*Driver) ReadWithJsoniter

func (t *Driver) ReadWithJsoniter(col string, key string, v interface{}) error

/ Read the object and unmarshal it to v, but with jsoniter encoder, this may speed up a little.

func (*Driver) TableName

func (t *Driver) TableName(col string) string

func (*Driver) TryCreateTable

func (t *Driver) TryCreateTable(col string) error

/ Try to create table for the collection

func (*Driver) Write

func (t *Driver) Write(col string, key string, i interface{}) error

/ Write an object

func (*Driver) WriteIgnore

func (t *Driver) WriteIgnore(col string, key string, i interface{}) error

/ Write an object only if it is altered. (Only do writing when the new data is different with the old data in db)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL