package redis import ( "github.com/gocontrib/log" "github.com/gocontrib/nosql" "github.com/gocontrib/nosql/kv" ) var debug = log.IfDebug("redis") func init() { data.RegisterDriver(&driver{}, "redis") } type driver struct{} func (d *driver) Open(url, db string) (data.Store, error) { // TODO support db parameter if it is not in URL return Open(url, false) } // Open redis store. func Open(url string, dropDatabase bool) (data.Store, error) { db, err := newRedisStore(url, dropDatabase) if err != nil { return nil, err } return New(db), nil } // New redis-like store.
package ledis import ( "os" "strconv" "github.com/gocontrib/log" "github.com/gocontrib/nosql" "github.com/gocontrib/nosql/redis" "github.com/siddontang/ledisdb/config" "github.com/siddontang/ledisdb/ledis" ) var debug = log.IfDebug("ledis") func init() { data.RegisterDriver(&driver{}, "ledis", "ledisdb") } type driver struct{} func (d *driver) Open(path, db string) (data.Store, error) { i, err := strconv.ParseInt(db, 10, 64) if err != nil { return nil, err } return Open(path, int(i), false) } // Open ledis store. func Open(path string, db int, dropDatabase bool) (data.Store, error) {
package postgresql import ( "database/sql" "fmt" "github.com/gocontrib/log" "github.com/gocontrib/nosql" "github.com/gocontrib/nosql/util" // load postgresql driver _ "github.com/lib/pq" ) var debug = log.IfDebug("postgresql") func init() { data.RegisterDriver(&driver{}, "pg", "postgre", "postgresql") } type driver struct{} func (d *driver) Open(url, db string) (data.Store, error) { return Open(url, db, false) } // Open postgresql data store. // dropDatabase only for testing use func Open(connectionURL string, databaseName string, dropDatabase bool) (data.Store, error) { constr := util.ReplaceEnv(connectionURL) var db, err = sql.Open("postgres", constr)
package kv import ( "github.com/gocontrib/log" ) var ( debug = log.IfDebug("kv") verbose = false ) type debugStore struct { db Store } func (t *debugStore) Begin(writable bool) (Tx, error) { debug.Info("db.Begin(%v)", writable) tx, err := t.db.Begin(writable) if err != nil { debug.Error("Begin failed: %v", err) return nil, err } return &debugTx{tx}, nil } func (t *debugStore) Close() error { debug.Info("db.Close()") var err = t.db.Close() if err != nil { debug.Error("Close failed: %v", err) }