Skip to content
write db yaml once, generate go orm code everywhere.
Go Other
  1. Go 99.3%
  2. Other 0.7%
Branch: master
Clone or download
scbizu Merge pull request #102 from ezbuy/fix/clean-spam-zset
parser: fix misorder of the pk keys
Latest commit 7c3dfbb Jun 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci ci: fix config.yml May 24, 2019
cmd move err check to object Feb 2, 2018
doc all: add gen pb support May 23, 2019
example
fs all: add gen pb support May 23, 2019
orm Feature/add trace (#86) Mar 12, 2019
parser parser: fix misorder of the pk keys Jun 12, 2019
tpl Merge pull request #96 from toukii/feature/index May 24, 2019
.gitignore git ignore Jul 6, 2018
LICENSE Initial commit Dec 30, 2016
Makefile sqlbuilder May 27, 2017
README.md
go.mod ci: add circleci May 24, 2019
go.sum ci: add circleci May 24, 2019
main.go

README.md

redis-orm

redis-orm fly orm up

features

quick start

generate command

$: go get github.com/ezbuy/redis-orm

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

read access usage

import "github.com/ezbuy/redis-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)

//! search usage
blogs, err := model.BlogDBMgr(db).Search("INNER JOIN users ON blog.user_id = users.user_id WHERE users.mail_box=?", "", "", "foo@bar.com")

//! fetch object 
model.UserDBMgr(db).Fetch(pk PrimaryKey) (*User, error)
model.UserDBMgr(db).FetchByPrimaryKey(id int32) (*User, error)
model.UserDBMgr(db).FetchByPrimaryKeys(ids []int32) ([]*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/ezbuy/redis-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).FetchByPrimaryKey(id int32) (*User, error)
model.UserDBMgr(tx).FetchByPrimaryKeys(ids []int32) ([]*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/ezbuy/redis-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)

redis-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

redis-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
You can’t perform that action at this time.