db-orm

command module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

README

db-orm

db-orm fly orm up

features

quick start

generate command
$: go get github.com/auto-program/db-orm

$: db-orm code -i example/yaml -o example/model

read access usage
import "github.com/auto-program/db-orm/example/model"

# mysql
model.MySQLSetup(cf)


db := model.MySQL()
//! query (ids []string) by unique & index & range definitions
model.UserDBMgr(db).FindOne(unique)
model.UserDBMgr(db).Find(index)
model.UserDBMgr(db).Range(scope)
model.UserDBMgr(db).RangeRevert(scope)

//! fetch object 
model.UserDBMgr(db).Fetch(pk PrimaryKey) (*User, error)
model.UserDBMgr(db).FetchByPrimaryKeys(pks []PrimaryKey) ([]*User, error)

# redis
model.RedisSetup(cf)

redis := model.Redis()
//! query (ids []string) by unique & index & range definitions
model.UserRedisMgr(redis).FindOne(unique)
model.UserRedisMgr(redis).Find(index)
model.UserRedisMgr(redis).Range(scope)
model.UserRedisMgr(redis).RangeRevert(scope)

//! fetch object 
model.UserRedisMgr(redis).Fetch(pk PrimaryKey) (*User, error)
model.UserRedisMgr(redis).FetchByPrimaryKeys(pks []PrimaryKey) ([]*User, error)


write access usage
import "github.com/auto-program/db-orm/example/model"

# mysql
model.MySQLSetup(cf)

db := model.MySQL()
tx, err := db.BeginTx()
defer tx.Close()

model.UserDBMgr(tx).Save(obj)
model.UserDBMgr(tx).Create(obj)
model.UserDBMgr(tx).Update(obj)
model.UserDBMgr(tx).Delete(obj)

model.UserDBMgr(tx).FindOne(unique)
model.UserDBMgr(tx).Find(index)
model.UserDBMgr(tx).Range(scope)
model.UserDBMgr(tx).RangeRevert(scope)

model.UserDBMgr(tx).Fetch(id string) (*User, error)
model.UserDBMgr(tx).FetchByPrimaryKeys(pks []PrimaryKey) ([]*User, error)

# redis
model.RedisSetup(cf)

redis := model.Redis()
model.UserRedisMgr(redis).Save(obj)
model.UserRedisMgr(redis).Create(obj)
model.UserRedisMgr(redis).Update(obj)
model.UserRedisMgr(redis).Delete(obj)

sync data
import "github.com/auto-program/db-orm/example/model"

model.MySQLSetup(cf)
model.RedisSetup(cf)

db := model.MySQL()
redis := model.Redis()

model.UserRedisMgr(redis).Load(model.UserDBMgr(db))

bench redis vs mysql

enviroment:

mysql-server, redis-server, test client all in the same machine (mac air)

db-orm.redis.bench

Ran 1000 samples:
unique.runtime:
  Fastest Time: 0.000s
  Slowest Time: 0.001s
  Average Time: 0.000s ± 0.000s
index.runtime:
  Fastest Time: 0.000s
  Slowest Time: 0.000s
  Average Time: 0.000s ± 0.000s
range.runtime:
  Fastest Time: 0.000s
  Slowest Time: 0.000s
  Average Time: 0.000s ± 0.000s
range.revert.runtime:
  Fastest Time: 0.000s
  Slowest Time: 0.000s
  Average Time: 0.000s ± 0.000s
fetch.runtime:
  Fastest Time: 0.002s
  Slowest Time: 0.004s
  Average Time: 0.002s ± 0.000s

db-orm.mysql.bench

Ran 1000 samples:
unique.runtime:
  Fastest Time: 0.002s
  Slowest Time: 0.106s
  Average Time: 0.003s ± 0.005s
index.runtime:
  Fastest Time: 0.002s
  Slowest Time: 0.106s
  Average Time: 0.003s ± 0.005s
range.runtime:
  Fastest Time: 0.002s
  Slowest Time: 0.105s
  Average Time: 0.002s ± 0.005s
range.revert.runtime:
  Fastest Time: 0.002s
  Slowest Time: 0.105s
  Average Time: 0.002s ± 0.006s
fetch.runtime:
  Fastest Time: 0.004s
  Slowest Time: 0.150s
  Average Time: 0.006s ± 0.009s

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
example
orm

Jump to

Keyboard shortcuts

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