diff --git a/db/check.go b/db/check.go index 9c0f4343..ebd831b3 100644 --- a/db/check.go +++ b/db/check.go @@ -76,7 +76,7 @@ func (d *document) grant(ctx context.Context, met method) (ok bool, err error) { // so we can check if the permissions // allow us to view this document. - tb, err := d.getTB() + tb, err := d.getTB(ctx) if err != nil { return false, err } @@ -156,7 +156,7 @@ func (d *document) allow(ctx context.Context, met method) (ok bool, err error) { // so we can check if the permissions // allow us to view this document. - tb, err := d.getTB() + tb, err := d.getTB(ctx) if err != nil { return false, err } diff --git a/db/define.go b/db/define.go index 136b69e0..8d424b08 100644 --- a/db/define.go +++ b/db/define.go @@ -28,7 +28,7 @@ func (e *executor) executeDefineNamespace(ctx context.Context, ast *sql.DefineNa // Save the namespace definition nkey := &keys.NS{KV: ast.KV, NS: ast.Name.ID} - _, err = e.dbo.Put(0, nkey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, nkey.Encode(), ast.Encode()) return @@ -36,11 +36,11 @@ func (e *executor) executeDefineNamespace(ctx context.Context, ast *sql.DefineNa func (e *executor) executeDefineDatabase(ctx context.Context, ast *sql.DefineDatabaseStatement) (out []interface{}, err error) { - e.dbo.AddNS(ast.NS) + e.dbo.AddNS(ctx, ast.NS) // Save the database definition dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID} - _, err = e.dbo.Put(0, dkey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, dkey.Encode(), ast.Encode()) return @@ -55,19 +55,19 @@ func (e *executor) executeDefineLogin(ctx context.Context, ast *sql.DefineLoginS switch ast.Kind { case sql.NAMESPACE: - e.dbo.AddNS(ast.NS) + e.dbo.AddNS(ctx, ast.NS) // Save the login definition ukey := &keys.NU{KV: ast.KV, NS: ast.NS, US: ast.User.ID} - _, err = e.dbo.Put(0, ukey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, ukey.Encode(), ast.Encode()) case sql.DATABASE: - e.dbo.AddDB(ast.NS, ast.DB) + e.dbo.AddDB(ctx, ast.NS, ast.DB) // Save the login definition ukey := &keys.DU{KV: ast.KV, NS: ast.NS, DB: ast.DB, US: ast.User.ID} - _, err = e.dbo.Put(0, ukey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, ukey.Encode(), ast.Encode()) } @@ -80,19 +80,19 @@ func (e *executor) executeDefineToken(ctx context.Context, ast *sql.DefineTokenS switch ast.Kind { case sql.NAMESPACE: - e.dbo.AddNS(ast.NS) + e.dbo.AddNS(ctx, ast.NS) // Save the token definition tkey := &keys.NT{KV: ast.KV, NS: ast.NS, TK: ast.Name.ID} - _, err = e.dbo.Put(0, tkey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, tkey.Encode(), ast.Encode()) case sql.DATABASE: - e.dbo.AddDB(ast.NS, ast.DB) + e.dbo.AddDB(ctx, ast.NS, ast.DB) // Save the token definition tkey := &keys.DT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TK: ast.Name.ID} - _, err = e.dbo.Put(0, tkey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, tkey.Encode(), ast.Encode()) } @@ -104,11 +104,11 @@ func (e *executor) executeDefineScope(ctx context.Context, ast *sql.DefineScopeS ast.Code = rand.New(128) - e.dbo.AddDB(ast.NS, ast.DB) + e.dbo.AddDB(ctx, ast.NS, ast.DB) // Remove the scope definition skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name.ID} - _, err = e.dbo.Put(0, skey.Encode(), ast.Encode()) + _, err = e.dbo.Put(ctx, 0, skey.Encode(), ast.Encode()) return @@ -118,11 +118,11 @@ func (e *executor) executeDefineEvent(ctx context.Context, ast *sql.DefineEventS for _, TB := range ast.What { - e.dbo.AddTB(ast.NS, ast.DB, TB.TB) + e.dbo.AddTB(ctx, ast.NS, ast.DB, TB.TB) // Remove the event definition ekey := &keys.EV{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, EV: ast.Name.ID} - if _, err = e.dbo.Put(0, ekey.Encode(), ast.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, ekey.Encode(), ast.Encode()); err != nil { return nil, err } @@ -136,11 +136,11 @@ func (e *executor) executeDefineField(ctx context.Context, ast *sql.DefineFieldS for _, TB := range ast.What { - e.dbo.AddTB(ast.NS, ast.DB, TB.TB) + e.dbo.AddTB(ctx, ast.NS, ast.DB, TB.TB) // Save the field definition fkey := &keys.FD{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, FD: ast.Name.ID} - if _, err = e.dbo.Put(0, fkey.Encode(), ast.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, fkey.Encode(), ast.Encode()); err != nil { return nil, err } @@ -154,17 +154,17 @@ func (e *executor) executeDefineIndex(ctx context.Context, ast *sql.DefineIndexS for _, TB := range ast.What { - e.dbo.AddTB(ast.NS, ast.DB, TB.TB) + e.dbo.AddTB(ctx, ast.NS, ast.DB, TB.TB) // Save the index definition ikey := &keys.IX{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, IX: ast.Name.ID} - if _, err = e.dbo.Put(0, ikey.Encode(), ast.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, ikey.Encode(), ast.Encode()); err != nil { return nil, err } // Remove the index resource data dkey := &keys.Index{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, IX: ast.Name.ID, FD: keys.Ignore} - if _, err = e.dbo.ClrP(dkey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, dkey.Encode(), 0); err != nil { return nil, err } @@ -183,7 +183,7 @@ func (e *executor) executeDefineIndex(ctx context.Context, ast *sql.DefineIndexS func (e *executor) executeDefineTable(ctx context.Context, ast *sql.DefineTableStatement) (out []interface{}, err error) { - e.dbo.AddDB(ast.NS, ast.DB) + e.dbo.AddDB(ctx, ast.NS, ast.DB) for _, TB := range ast.What { @@ -191,7 +191,7 @@ func (e *executor) executeDefineTable(ctx context.Context, ast *sql.DefineTableS // Save the table definition tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB} - if _, err = e.dbo.Put(0, tkey.Encode(), ast.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, tkey.Encode(), ast.Encode()); err != nil { return nil, err } @@ -199,7 +199,7 @@ func (e *executor) executeDefineTable(ctx context.Context, ast *sql.DefineTableS // Remove the table resource data dkey := &keys.Table{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB} - if _, err = e.dbo.ClrP(dkey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, dkey.Encode(), 0); err != nil { return nil, err } @@ -207,7 +207,7 @@ func (e *executor) executeDefineTable(ctx context.Context, ast *sql.DefineTableS // Save the foreign table definition tkey := &keys.FT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: FT.TB, FT: TB.TB} - if _, err = e.dbo.Put(0, tkey.Encode(), ast.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, tkey.Encode(), ast.Encode()); err != nil { return nil, err } diff --git a/db/document.go b/db/document.go index 65205257..313b10bf 100644 --- a/db/document.go +++ b/db/document.go @@ -92,50 +92,50 @@ func (d *document) erase() (err error) { return } -func (d *document) getTB() (out *sql.DefineTableStatement, err error) { +func (d *document) getTB(ctx context.Context) (out *sql.DefineTableStatement, err error) { if !d.store.tb { d.store.tb = true - d.cache.tb, err = d.i.e.dbo.GetTB(d.key.NS, d.key.DB, d.key.TB) + d.cache.tb, err = d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) } return d.cache.tb, err } -func (d *document) getEV() (out []*sql.DefineEventStatement, err error) { +func (d *document) getEV(ctx context.Context) (out []*sql.DefineEventStatement, err error) { if !d.store.ev { d.store.ev = true - d.cache.ev, err = d.i.e.dbo.AllEV(d.key.NS, d.key.DB, d.key.TB) + d.cache.ev, err = d.i.e.dbo.AllEV(ctx, d.key.NS, d.key.DB, d.key.TB) } return d.cache.ev, err } -func (d *document) getFD() (out []*sql.DefineFieldStatement, err error) { +func (d *document) getFD(ctx context.Context) (out []*sql.DefineFieldStatement, err error) { if !d.store.fd { d.store.fd = true - d.cache.fd, err = d.i.e.dbo.AllFD(d.key.NS, d.key.DB, d.key.TB) + d.cache.fd, err = d.i.e.dbo.AllFD(ctx, d.key.NS, d.key.DB, d.key.TB) } return d.cache.fd, err } -func (d *document) getIX() (out []*sql.DefineIndexStatement, err error) { +func (d *document) getIX(ctx context.Context) (out []*sql.DefineIndexStatement, err error) { if !d.store.ix { d.store.ix = true - d.cache.ix, err = d.i.e.dbo.AllIX(d.key.NS, d.key.DB, d.key.TB) + d.cache.ix, err = d.i.e.dbo.AllIX(ctx, d.key.NS, d.key.DB, d.key.TB) } return d.cache.ix, err } -func (d *document) getFT() (out []*sql.DefineTableStatement, err error) { +func (d *document) getFT(ctx context.Context) (out []*sql.DefineTableStatement, err error) { if !d.store.ft { d.store.ft = true - d.cache.ft, err = d.i.e.dbo.AllFT(d.key.NS, d.key.DB, d.key.TB) + d.cache.ft, err = d.i.e.dbo.AllFT(ctx, d.key.NS, d.key.DB, d.key.TB) } return d.cache.ft, err } -func (d *document) getLV() (out []*sql.LiveStatement, err error) { +func (d *document) getLV(ctx context.Context) (out []*sql.LiveStatement, err error) { if !d.store.lv { d.store.lv = true - d.cache.lv, err = d.i.e.dbo.AllLV(d.key.NS, d.key.DB, d.key.TB) + d.cache.lv, err = d.i.e.dbo.AllLV(ctx, d.key.NS, d.key.DB, d.key.TB) } return d.cache.lv, err } @@ -224,7 +224,7 @@ func (d *document) setup(ctx context.Context) (err error) { // to be loaded from the KV store. if d.key != nil && d.val == nil { - d.val, err = d.i.e.dbo.Get(d.i.versn, d.key.Encode()) + d.val, err = d.i.e.dbo.Get(ctx, d.i.versn, d.key.Encode()) if err != nil { return } @@ -332,7 +332,7 @@ func (d *document) shouldDrop(ctx context.Context) (bool, error) { // that the table should drop // writes, and if so, then return. - tb, err := d.getTB() + tb, err := d.getTB(ctx) if err != nil { return false, err } @@ -362,7 +362,7 @@ func (d *document) storeThing(ctx context.Context) (err error) { // Write the value to the data // layer and return any errors. - _, err = d.i.e.dbo.Put(d.i.e.time, d.key.Encode(), d.current.Encode()) + _, err = d.i.e.dbo.Put(ctx, d.i.e.time, d.key.Encode(), d.current.Encode()) return @@ -382,7 +382,7 @@ func (d *document) purgeThing(ctx context.Context) (err error) { // Reset the item by writing a // nil value to the storage. - _, err = d.i.e.dbo.Put(d.i.e.time, d.key.Encode(), nil) + _, err = d.i.e.dbo.Put(ctx, d.i.e.time, d.key.Encode(), nil) return @@ -402,7 +402,7 @@ func (d *document) eraseThing(ctx context.Context) (err error) { // Delete the item entirely from // storage, so no versions exist. - _, err = d.i.e.dbo.Clr(d.key.Encode()) + _, err = d.i.e.dbo.Clr(ctx, d.key.Encode()) return @@ -433,7 +433,7 @@ func (d *document) storeIndex(ctx context.Context) (err error) { // for this table, loop through // them, and compute the changes. - ixs, err := d.getIX() + ixs, err := d.getIX(ctx) if err != nil { return err } @@ -450,11 +450,11 @@ func (d *document) storeIndex(ctx context.Context) (err error) { if ix.Uniq == true { for _, v := range del { didx := &keys.Index{KV: d.key.KV, NS: d.key.NS, DB: d.key.DB, TB: d.key.TB, IX: ix.Name.ID, FD: v} - d.i.e.dbo.DelC(d.i.e.time, didx.Encode(), d.id.Bytes()) + d.i.e.dbo.DelC(ctx, d.i.e.time, didx.Encode(), d.id.Bytes()) } for _, v := range add { aidx := &keys.Index{KV: d.key.KV, NS: d.key.NS, DB: d.key.DB, TB: d.key.TB, IX: ix.Name.ID, FD: v} - if _, err = d.i.e.dbo.PutC(0, aidx.Encode(), d.id.Bytes(), nil); err != nil { + if _, err = d.i.e.dbo.PutC(ctx, 0, aidx.Encode(), d.id.Bytes(), nil); err != nil { return &IndexError{tb: d.key.TB, name: ix.Name, cols: ix.Cols, vals: v} } } @@ -463,11 +463,11 @@ func (d *document) storeIndex(ctx context.Context) (err error) { if ix.Uniq == false { for _, v := range del { didx := &keys.Point{KV: d.key.KV, NS: d.key.NS, DB: d.key.DB, TB: d.key.TB, IX: ix.Name.ID, FD: v, ID: d.key.ID} - d.i.e.dbo.DelC(d.i.e.time, didx.Encode(), d.id.Bytes()) + d.i.e.dbo.DelC(ctx, d.i.e.time, didx.Encode(), d.id.Bytes()) } for _, v := range add { aidx := &keys.Point{KV: d.key.KV, NS: d.key.NS, DB: d.key.DB, TB: d.key.TB, IX: ix.Name.ID, FD: v, ID: d.key.ID} - if _, err = d.i.e.dbo.PutC(0, aidx.Encode(), d.id.Bytes(), nil); err != nil { + if _, err = d.i.e.dbo.PutC(ctx, 0, aidx.Encode(), d.id.Bytes(), nil); err != nil { return &IndexError{tb: d.key.TB, name: ix.Name, cols: ix.Cols, vals: v} } } @@ -504,7 +504,7 @@ func (d *document) purgeIndex(ctx context.Context) (err error) { // for this table, loop through // them, and compute the changes. - ixs, err := d.getIX() + ixs, err := d.getIX(ctx) if err != nil { return err } @@ -516,14 +516,14 @@ func (d *document) purgeIndex(ctx context.Context) (err error) { if ix.Uniq == true { for _, v := range del { key := &keys.Index{KV: d.key.KV, NS: d.key.NS, DB: d.key.DB, TB: d.key.TB, IX: ix.Name.ID, FD: v} - d.i.e.dbo.DelC(0, key.Encode(), d.id.Bytes()) + d.i.e.dbo.DelC(ctx, 0, key.Encode(), d.id.Bytes()) } } if ix.Uniq == false { for _, v := range del { key := &keys.Point{KV: d.key.KV, NS: d.key.NS, DB: d.key.DB, TB: d.key.TB, IX: ix.Name.ID, FD: v, ID: d.key.ID} - d.i.e.dbo.DelC(0, key.Encode(), d.id.Bytes()) + d.i.e.dbo.DelC(ctx, 0, key.Encode(), d.id.Bytes()) } } diff --git a/db/event.go b/db/event.go index b05367a6..f1f27445 100644 --- a/db/event.go +++ b/db/event.go @@ -43,7 +43,7 @@ func (d *document) event(ctx context.Context, met method) (err error) { // for this table, loop through // them, and compute the events. - evs, err := d.getEV() + evs, err := d.getEV(ctx) if err != nil { return err } diff --git a/db/info.go b/db/info.go index f607aa42..e67b692e 100644 --- a/db/info.go +++ b/db/info.go @@ -38,17 +38,17 @@ func (e *executor) executeInfo(ctx context.Context, ast *sql.InfoStatement) (out func (e *executor) executeInfoNS(ctx context.Context, ast *sql.InfoStatement) (out []interface{}, err error) { - db, err := e.dbo.AllDB(ast.NS) + db, err := e.dbo.AllDB(ctx, ast.NS) if err != nil { return nil, err } - nt, err := e.dbo.AllNT(ast.NS) + nt, err := e.dbo.AllNT(ctx, ast.NS) if err != nil { return nil, err } - nu, err := e.dbo.AllNU(ast.NS) + nu, err := e.dbo.AllNU(ctx, ast.NS) if err != nil { return nil, err } @@ -80,22 +80,22 @@ func (e *executor) executeInfoNS(ctx context.Context, ast *sql.InfoStatement) (o func (e *executor) executeInfoDB(ctx context.Context, ast *sql.InfoStatement) (out []interface{}, err error) { - tb, err := e.dbo.AllTB(ast.NS, ast.DB) + tb, err := e.dbo.AllTB(ctx, ast.NS, ast.DB) if err != nil { return nil, err } - dt, err := e.dbo.AllDT(ast.NS, ast.DB) + dt, err := e.dbo.AllDT(ctx, ast.NS, ast.DB) if err != nil { return nil, err } - du, err := e.dbo.AllDU(ast.NS, ast.DB) + du, err := e.dbo.AllDU(ctx, ast.NS, ast.DB) if err != nil { return nil, err } - sc, err := e.dbo.AllSC(ast.NS, ast.DB) + sc, err := e.dbo.AllSC(ctx, ast.NS, ast.DB) if err != nil { return nil, err } @@ -133,27 +133,27 @@ func (e *executor) executeInfoDB(ctx context.Context, ast *sql.InfoStatement) (o func (e *executor) executeInfoTB(ctx context.Context, ast *sql.InfoStatement) (out []interface{}, err error) { - ev, err := e.dbo.AllEV(ast.NS, ast.DB, ast.What.TB) + ev, err := e.dbo.AllEV(ctx, ast.NS, ast.DB, ast.What.TB) if err != nil { return nil, err } - fd, err := e.dbo.AllFD(ast.NS, ast.DB, ast.What.TB) + fd, err := e.dbo.AllFD(ctx, ast.NS, ast.DB, ast.What.TB) if err != nil { return nil, err } - ix, err := e.dbo.AllIX(ast.NS, ast.DB, ast.What.TB) + ix, err := e.dbo.AllIX(ctx, ast.NS, ast.DB, ast.What.TB) if err != nil { return nil, err } - lv, err := e.dbo.AllLV(ast.NS, ast.DB, ast.What.TB) + lv, err := e.dbo.AllLV(ctx, ast.NS, ast.DB, ast.What.TB) if err != nil { return nil, err } - ft, err := e.dbo.AllFT(ast.NS, ast.DB, ast.What.TB) + ft, err := e.dbo.AllFT(ctx, ast.NS, ast.DB, ast.What.TB) if err != nil { return nil, err } diff --git a/db/iterator.go b/db/iterator.go index 3026ab48..d286bc0c 100644 --- a/db/iterator.go +++ b/db/iterator.go @@ -388,7 +388,7 @@ func (i *iterator) processPerms(ctx context.Context, nsv, dbv, tbv string) { // we need to fetch the table to ensure // that the table is not a view table. - tb, i.err = i.e.dbo.AddTB(nsv, dbv, tbv) + tb, i.err = i.e.dbo.AddTB(ctx, nsv, dbv, tbv) if i.err != nil { close(i.stop) return @@ -429,7 +429,7 @@ func (i *iterator) processPerms(ctx context.Context, nsv, dbv, tbv string) { // otherwise, the scoped authentication // request can not do anything. - _, i.err = i.e.dbo.GetNS(nsv) + _, i.err = i.e.dbo.GetNS(ctx, nsv) if i.err != nil { close(i.stop) return @@ -439,7 +439,7 @@ func (i *iterator) processPerms(ctx context.Context, nsv, dbv, tbv string) { // otherwise, the scoped authentication // request can not do anything. - _, i.err = i.e.dbo.GetDB(nsv, dbv) + _, i.err = i.e.dbo.GetDB(ctx, nsv, dbv) if i.err != nil { close(i.stop) return @@ -458,7 +458,7 @@ func (i *iterator) processPerms(ctx context.Context, nsv, dbv, tbv string) { // otherwise, the scoped authentication // request can not do anything. - tb, i.err = i.e.dbo.GetTB(nsv, dbv, tbv) + tb, i.err = i.e.dbo.GetTB(ctx, nsv, dbv, tbv) if i.err != nil { close(i.stop) return @@ -569,7 +569,7 @@ func (i *iterator) processTable(ctx context.Context, key *keys.Table) { return } - vals, i.err = i.e.dbo.GetR(i.versn, min, max, 10000) + vals, i.err = i.e.dbo.GetR(ctx, i.versn, min, max, 10000) if i.err != nil { close(i.stop) return diff --git a/db/lives.go b/db/lives.go index cd604b57..0ec1e224 100644 --- a/db/lives.go +++ b/db/lives.go @@ -48,7 +48,7 @@ func (d *document) lives(ctx context.Context, when method) (err error) { // specified for this table, and // update values which have changed. - lvs, err := d.getLV() + lvs, err := d.getLV(ctx) if err != nil { return err } diff --git a/db/merge.go b/db/merge.go index f602b096..66ce158a 100644 --- a/db/merge.go +++ b/db/merge.go @@ -98,7 +98,7 @@ func (d *document) defFld(ctx context.Context, met method) (err error) { func (d *document) delFld(ctx context.Context, met method) (err error) { - tb, err := d.getTB() + tb, err := d.getTB(ctx) if err != nil { return err } @@ -109,7 +109,7 @@ func (d *document) delFld(ctx context.Context, met method) (err error) { // Get the defined fields - fds, err := d.getFD() + fds, err := d.getFD(ctx) if err != nil { return err } @@ -267,7 +267,7 @@ func (d *document) mrgSet(ctx context.Context, met method, expr *sql.DataExpress func (d *document) mrgFld(ctx context.Context, met method) (err error) { - fds, err := d.getFD() + fds, err := d.getFD(ctx) if err != nil { return err } diff --git a/db/perms.go b/db/perms.go index cd70344b..d524be63 100644 --- a/db/perms.go +++ b/db/perms.go @@ -37,7 +37,7 @@ func (d *document) perms(ctx context.Context, doc *data.Doc) (err error) { // check if the permissions allow us // to view each field. - fds, err := d.getFD() + fds, err := d.getFD(ctx) if err != nil { return err } diff --git a/db/remove.go b/db/remove.go index 6f3f9b26..e8e9e5f9 100644 --- a/db/remove.go +++ b/db/remove.go @@ -27,11 +27,11 @@ func (e *executor) executeRemoveNamespace(ctx context.Context, ast *sql.RemoveNa // Remove the namespace definition nkey := &keys.NS{KV: ast.KV, NS: ast.Name.ID} - _, err = e.dbo.Clr(nkey.Encode()) + _, err = e.dbo.Clr(ctx, nkey.Encode()) // Remove the namespace resource data akey := &keys.Namespace{KV: ast.KV, NS: ast.Name.ID} - _, err = e.dbo.ClrP(akey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, akey.Encode(), 0) return @@ -43,11 +43,11 @@ func (e *executor) executeRemoveDatabase(ctx context.Context, ast *sql.RemoveDat // Remove the database definition dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID} - _, err = e.dbo.Clr(dkey.Encode()) + _, err = e.dbo.Clr(ctx, dkey.Encode()) // Remove the database resource data akey := &keys.Database{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID} - _, err = e.dbo.ClrP(akey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, akey.Encode(), 0) return @@ -60,13 +60,13 @@ func (e *executor) executeRemoveLogin(ctx context.Context, ast *sql.RemoveLoginS // Remove the login definition ukey := &keys.NU{KV: ast.KV, NS: ast.NS, US: ast.User.ID} - _, err = e.dbo.ClrP(ukey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, ukey.Encode(), 0) case sql.DATABASE: // Remove the login definition ukey := &keys.DU{KV: ast.KV, NS: ast.NS, DB: ast.DB, US: ast.User.ID} - _, err = e.dbo.ClrP(ukey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, ukey.Encode(), 0) } @@ -81,13 +81,13 @@ func (e *executor) executeRemoveToken(ctx context.Context, ast *sql.RemoveTokenS // Remove the token definition tkey := &keys.NT{KV: ast.KV, NS: ast.NS, TK: ast.Name.ID} - _, err = e.dbo.ClrP(tkey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, tkey.Encode(), 0) case sql.DATABASE: // Remove the token definition tkey := &keys.DT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TK: ast.Name.ID} - _, err = e.dbo.ClrP(tkey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, tkey.Encode(), 0) } @@ -99,7 +99,7 @@ func (e *executor) executeRemoveScope(ctx context.Context, ast *sql.RemoveScopeS // Remove the scope definition skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name.ID} - _, err = e.dbo.ClrP(skey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, skey.Encode(), 0) return @@ -113,7 +113,7 @@ func (e *executor) executeRemoveEvent(ctx context.Context, ast *sql.RemoveEventS // Remove the event definition ekey := &keys.EV{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, EV: ast.Name.ID} - if _, err = e.dbo.ClrP(ekey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, ekey.Encode(), 0); err != nil { return nil, err } @@ -131,7 +131,7 @@ func (e *executor) executeRemoveField(ctx context.Context, ast *sql.RemoveFieldS // Remove the field definition fkey := &keys.FD{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, FD: ast.Name.ID} - if _, err = e.dbo.ClrP(fkey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, fkey.Encode(), 0); err != nil { return nil, err } @@ -149,13 +149,13 @@ func (e *executor) executeRemoveIndex(ctx context.Context, ast *sql.RemoveIndexS // Remove the index definition ikey := &keys.IX{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, IX: ast.Name.ID} - if _, err = e.dbo.ClrP(ikey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, ikey.Encode(), 0); err != nil { return nil, err } // Remove the index resource data dkey := &keys.Index{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB, IX: ast.Name.ID, FD: keys.Ignore} - if _, err = e.dbo.ClrP(dkey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, dkey.Encode(), 0); err != nil { return nil, err } @@ -171,21 +171,21 @@ func (e *executor) executeRemoveTable(ctx context.Context, ast *sql.RemoveTableS e.dbo.DelTB(ast.NS, ast.DB, TB.TB) - tb, err := e.dbo.GetTB(ast.NS, ast.DB, TB.TB) + tb, err := e.dbo.GetTB(ctx, ast.NS, ast.DB, TB.TB) if err != nil { return nil, err } // Remove the table definition tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB} - _, err = e.dbo.Clr(tkey.Encode()) + _, err = e.dbo.Clr(ctx, tkey.Encode()) if err != nil { return nil, err } // Remove the table resource data dkey := &keys.Table{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB} - _, err = e.dbo.ClrP(dkey.Encode(), 0) + _, err = e.dbo.ClrP(ctx, dkey.Encode(), 0) if err != nil { return nil, err } @@ -196,7 +196,7 @@ func (e *executor) executeRemoveTable(ctx context.Context, ast *sql.RemoveTableS // Remove the foreign table definition tkey := &keys.FT{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: FT.TB, FT: TB.TB} - if _, err = e.dbo.ClrP(tkey.Encode(), 0); err != nil { + if _, err = e.dbo.ClrP(ctx, tkey.Encode(), 0); err != nil { return nil, err } diff --git a/db/socket.go b/db/socket.go index 8f9a9a7e..18f6320e 100644 --- a/db/socket.go +++ b/db/socket.go @@ -157,7 +157,7 @@ func (s *socket) check(e *executor, ctx context.Context, ns, db, tb string) (err // otherwise, the scoped authentication // request can not do anything. - _, err = e.dbo.GetNS(ns) + _, err = e.dbo.GetNS(ctx, ns) if err != nil { return err } @@ -166,7 +166,7 @@ func (s *socket) check(e *executor, ctx context.Context, ns, db, tb string) (err // otherwise, the scoped authentication // request can not do anything. - _, err = e.dbo.GetDB(ns, db) + _, err = e.dbo.GetDB(ctx, ns, db) if err != nil { return err } @@ -175,7 +175,7 @@ func (s *socket) check(e *executor, ctx context.Context, ns, db, tb string) (err // otherwise, the scoped authentication // request can not do anything. - tbv, err = e.dbo.GetTB(ns, db, tb) + tbv, err = e.dbo.GetTB(ctx, ns, db, tb) if err != nil { return err } @@ -222,7 +222,9 @@ func (s *socket) deregister(id string) { sockets.Delete(id) - txn, _ := db.Begin(context.Background(), true) + ctx := context.Background() + + txn, _ := db.Begin(ctx, true) defer txn.Commit() @@ -235,12 +237,12 @@ func (s *socket) deregister(id string) { case *sql.Table: key := &keys.LV{KV: stm.KV, NS: stm.NS, DB: stm.DB, TB: what.TB, LV: id} - txn.Clr(key.Encode()) + txn.Clr(ctx, key.Encode()) case *sql.Ident: key := &keys.LV{KV: stm.KV, NS: stm.NS, DB: stm.DB, TB: what.ID, LV: id} - txn.Clr(key.Encode()) + txn.Clr(ctx, key.Encode()) } @@ -291,7 +293,7 @@ func (s *socket) executeLive(e *executor, ctx context.Context, stm *sql.LiveStat } key := &keys.LV{KV: stm.KV, NS: stm.NS, DB: stm.DB, TB: what.TB, LV: stm.ID} - if _, err = e.dbo.Put(0, key.Encode(), stm.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, key.Encode(), stm.Encode()); err != nil { return nil, err } @@ -302,7 +304,7 @@ func (s *socket) executeLive(e *executor, ctx context.Context, stm *sql.LiveStat } key := &keys.LV{KV: stm.KV, NS: stm.NS, DB: stm.DB, TB: what.ID, LV: stm.ID} - if _, err = e.dbo.Put(0, key.Encode(), stm.Encode()); err != nil { + if _, err = e.dbo.Put(ctx, 0, key.Encode(), stm.Encode()); err != nil { return nil, err } @@ -352,11 +354,11 @@ func (s *socket) executeKill(e *executor, ctx context.Context, stm *sql.KillStat case *sql.Table: key := &keys.LV{KV: qry.KV, NS: qry.NS, DB: qry.DB, TB: what.TB, LV: qry.ID} - _, err = e.dbo.Clr(key.Encode()) + _, err = e.dbo.Clr(ctx, key.Encode()) case *sql.Ident: key := &keys.LV{KV: qry.KV, NS: qry.NS, DB: qry.DB, TB: what.ID, LV: qry.ID} - _, err = e.dbo.Clr(key.Encode()) + _, err = e.dbo.Clr(ctx, key.Encode()) } diff --git a/db/table.go b/db/table.go index 98028324..f6390112 100644 --- a/db/table.go +++ b/db/table.go @@ -47,7 +47,7 @@ func (d *document) table(ctx context.Context, when method) (err error) { // specified for this table, and // update values which have changed. - fts, err := d.getFT() + fts, err := d.getFT(ctx) if err != nil { return err } diff --git a/kvs/mysql/tx.go b/kvs/mysql/tx.go index 26e533ce..eea33308 100644 --- a/kvs/mysql/tx.go +++ b/kvs/mysql/tx.go @@ -18,6 +18,8 @@ import ( "math" "sync" + "context" + "database/sql" "github.com/abcum/surreal/cnf" @@ -141,7 +143,7 @@ func (tx *TX) Commit() error { return tx.pntr.Commit() } -func (tx *TX) Clr(key []byte) (kvs.KV, error) { +func (tx *TX) Clr(ctx context.Context, key []byte) (kvs.KV, error) { var err error var res *sql.Rows @@ -150,16 +152,16 @@ func (tx *TX) Clr(key []byte) (kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.clr == nil { - tx.stmt.clr, _ = tx.pntr.Prepare(sqlClr) + tx.stmt.clr, _ = tx.pntr.PrepareContext(ctx, sqlClr) } - res, err = tx.stmt.clr.Query(key) + res, err = tx.stmt.clr.QueryContext(ctx, key) return one(res, err) } -func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) ClrP(ctx context.Context, key []byte, max uint64) ([]kvs.KV, error) { var err error var res *sql.Rows @@ -172,16 +174,16 @@ func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.clrP == nil { - tx.stmt.clrP, _ = tx.pntr.Prepare(sqlClrP) + tx.stmt.clrP, _ = tx.pntr.PrepareContext(ctx, sqlClrP) } - res, err = tx.stmt.clrP.Query(key, max) + res, err = tx.stmt.clrP.QueryContext(ctx, key, max) return many(res, err) } -func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) ClrR(ctx context.Context, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { var err error var res *sql.Rows @@ -194,16 +196,16 @@ func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.clrR == nil { - tx.stmt.clrR, _ = tx.pntr.Prepare(sqlClrR) + tx.stmt.clrR, _ = tx.pntr.PrepareContext(ctx, sqlClrR) } - res, err = tx.stmt.clrR.Query(beg, end, max) + res, err = tx.stmt.clrR.QueryContext(ctx, beg, end, max) return many(res, err) } -func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { +func (tx *TX) Get(ctx context.Context, ver int64, key []byte) (kvs.KV, error) { var err error var res *sql.Rows @@ -212,16 +214,16 @@ func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.get == nil { - tx.stmt.get, _ = tx.pntr.Prepare(sqlGet) + tx.stmt.get, _ = tx.pntr.PrepareContext(ctx, sqlGet) } - res, err = tx.stmt.get.Query(ver, key) + res, err = tx.stmt.get.QueryContext(ctx, ver, key) return one(res, err) } -func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) GetP(ctx context.Context, ver int64, key []byte, max uint64) ([]kvs.KV, error) { var err error var res *sql.Rows @@ -234,16 +236,16 @@ func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.getP == nil { - tx.stmt.getP, _ = tx.pntr.Prepare(sqlGetP) + tx.stmt.getP, _ = tx.pntr.PrepareContext(ctx, sqlGetP) } - res, err = tx.stmt.getP.Query(ver, key, max) + res, err = tx.stmt.getP.QueryContext(ctx, ver, key, max) return many(res, err) } -func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) GetR(ctx context.Context, ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { var err error var res *sql.Rows @@ -256,16 +258,16 @@ func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, err defer tx.lock.Unlock() if tx.stmt.getR == nil { - tx.stmt.getR, _ = tx.pntr.Prepare(sqlGetR) + tx.stmt.getR, _ = tx.pntr.PrepareContext(ctx, sqlGetR) } - res, err = tx.stmt.getR.Query(ver, beg, end, max) + res, err = tx.stmt.getR.QueryContext(ctx, ver, beg, end, max) return many(res, err) } -func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) { +func (tx *TX) Del(ctx context.Context, ver int64, key []byte) (kvs.KV, error) { var err error var res *sql.Rows @@ -274,16 +276,16 @@ func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.del == nil { - tx.stmt.del, _ = tx.pntr.Prepare(sqlDel) + tx.stmt.del, _ = tx.pntr.PrepareContext(ctx, sqlDel) } - res, err = tx.stmt.del.Query(ver, key) + res, err = tx.stmt.del.QueryContext(ctx, ver, key) return one(res, err) } -func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { +func (tx *TX) DelC(ctx context.Context, ver int64, key []byte, exp []byte) (kvs.KV, error) { var err error var now kvs.KV @@ -295,10 +297,10 @@ func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { // Get the item at the key if tx.stmt.get == nil { - tx.stmt.get, _ = tx.pntr.Prepare(sqlGet) + tx.stmt.get, _ = tx.pntr.PrepareContext(ctx, sqlGet) } - res, err = tx.stmt.get.Query(ver, key) + res, err = tx.stmt.get.QueryContext(ctx, ver, key) if err != nil { return nil, err } @@ -317,16 +319,16 @@ func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { // If they match then delete if tx.stmt.del == nil { - tx.stmt.del, _ = tx.pntr.Prepare(sqlDel) + tx.stmt.del, _ = tx.pntr.PrepareContext(ctx, sqlDel) } - res, err = tx.stmt.del.Query(ver, key) + res, err = tx.stmt.del.QueryContext(ctx, ver, key) return one(res, err) } -func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) DelP(ctx context.Context, ver int64, key []byte, max uint64) ([]kvs.KV, error) { var err error var res *sql.Rows @@ -339,16 +341,16 @@ func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.delP == nil { - tx.stmt.delP, _ = tx.pntr.Prepare(sqlDelP) + tx.stmt.delP, _ = tx.pntr.PrepareContext(ctx, sqlDelP) } - res, err = tx.stmt.delP.Query(ver, key, max) + res, err = tx.stmt.delP.QueryContext(ctx, ver, key, max) return many(res, err) } -func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) DelR(ctx context.Context, ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { var err error var res *sql.Rows @@ -361,16 +363,16 @@ func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, err defer tx.lock.Unlock() if tx.stmt.delR == nil { - tx.stmt.delR, _ = tx.pntr.Prepare(sqlDelR) + tx.stmt.delR, _ = tx.pntr.PrepareContext(ctx, sqlDelR) } - res, err = tx.stmt.delR.Query(ver, beg, end, max) + res, err = tx.stmt.delR.QueryContext(ctx, ver, beg, end, max) return many(res, err) } -func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) { +func (tx *TX) Put(ctx context.Context, ver int64, key []byte, val []byte) (kvs.KV, error) { var err error var res *sql.Rows @@ -384,16 +386,16 @@ func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) { defer tx.lock.Unlock() if tx.stmt.put == nil { - tx.stmt.put, _ = tx.pntr.Prepare(sqlPut) + tx.stmt.put, _ = tx.pntr.PrepareContext(ctx, sqlPut) } - res, err = tx.stmt.put.Query(ver, key, val, val) + res, err = tx.stmt.put.QueryContext(ctx, ver, key, val, val) return one(res, err) } -func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) { +func (tx *TX) PutC(ctx context.Context, ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) { var err error var now kvs.KV @@ -409,10 +411,10 @@ func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error case nil: if tx.stmt.putN == nil { - tx.stmt.putN, _ = tx.pntr.Prepare(sqlPutN) + tx.stmt.putN, _ = tx.pntr.PrepareContext(ctx, sqlPutN) } - res, err = tx.stmt.putN.Query(ver, key, val) + res, err = tx.stmt.putN.QueryContext(ctx, ver, key, val) return one(res, err) @@ -421,10 +423,10 @@ func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error // Get the item at the key if tx.stmt.get == nil { - tx.stmt.get, _ = tx.pntr.Prepare(sqlGet) + tx.stmt.get, _ = tx.pntr.PrepareContext(ctx, sqlGet) } - res, err = tx.stmt.get.Query(ver, key) + res, err = tx.stmt.get.QueryContext(ctx, ver, key) if err != nil { return nil, err } @@ -443,10 +445,10 @@ func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error // If they match then delete if tx.stmt.del == nil { - tx.stmt.put, _ = tx.pntr.Prepare(sqlPut) + tx.stmt.put, _ = tx.pntr.PrepareContext(ctx, sqlPut) } - res, err = tx.stmt.put.Query(ver, key, val, val) + res, err = tx.stmt.put.QueryContext(ctx, ver, key, val, val) return one(res, err) diff --git a/kvs/rixxdb/tx.go b/kvs/rixxdb/tx.go index b44d2a85..8af1ec98 100644 --- a/kvs/rixxdb/tx.go +++ b/kvs/rixxdb/tx.go @@ -15,6 +15,8 @@ package rixxdb import ( + "context" + "github.com/abcum/rixxdb" "github.com/abcum/surreal/kvs" ) @@ -71,62 +73,62 @@ func (tx *TX) Commit() error { return tx.pntr.Commit() } -func (tx *TX) Clr(key []byte) (kvs.KV, error) { +func (tx *TX) Clr(ctx context.Context, key []byte) (kvs.KV, error) { res, err := tx.pntr.Clr(key) return one(res, err) } -func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) ClrP(ctx context.Context, key []byte, max uint64) ([]kvs.KV, error) { res, err := tx.pntr.ClrP(key, max) return many(res, err) } -func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) ClrR(ctx context.Context, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { res, err := tx.pntr.ClrR(beg, end, max) return many(res, err) } -func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { +func (tx *TX) Get(ctx context.Context, ver int64, key []byte) (kvs.KV, error) { res, err := tx.pntr.Get(uint64(ver), key) return one(res, err) } -func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) GetP(ctx context.Context, ver int64, key []byte, max uint64) ([]kvs.KV, error) { res, err := tx.pntr.GetP(uint64(ver), key, max) return many(res, err) } -func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) GetR(ctx context.Context, ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { res, err := tx.pntr.GetR(uint64(ver), beg, end, max) return many(res, err) } -func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) { +func (tx *TX) Del(ctx context.Context, ver int64, key []byte) (kvs.KV, error) { res, err := tx.pntr.Del(uint64(ver), key) return one(res, err) } -func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { +func (tx *TX) DelC(ctx context.Context, ver int64, key []byte, exp []byte) (kvs.KV, error) { res, err := tx.pntr.DelC(uint64(ver), key, exp) return one(res, err) } -func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) DelP(ctx context.Context, ver int64, key []byte, max uint64) ([]kvs.KV, error) { res, err := tx.pntr.DelP(uint64(ver), key, max) return many(res, err) } -func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { +func (tx *TX) DelR(ctx context.Context, ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { res, err := tx.pntr.DelR(uint64(ver), beg, end, max) return many(res, err) } -func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) { +func (tx *TX) Put(ctx context.Context, ver int64, key []byte, val []byte) (kvs.KV, error) { res, err := tx.pntr.Put(uint64(ver), key, val) return one(res, err) } -func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) { +func (tx *TX) PutC(ctx context.Context, ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) { res, err := tx.pntr.PutC(uint64(ver), key, val, exp) return one(res, err) } diff --git a/kvs/tx.go b/kvs/tx.go index 7e543df7..242f658f 100644 --- a/kvs/tx.go +++ b/kvs/tx.go @@ -14,25 +14,27 @@ package kvs +import "context" + // TX represents a database transaction type TX interface { Closed() bool Cancel() error Commit() error - Clr([]byte) (KV, error) - ClrP([]byte, uint64) ([]KV, error) - ClrR([]byte, []byte, uint64) ([]KV, error) + Clr(context.Context, []byte) (KV, error) + ClrP(context.Context, []byte, uint64) ([]KV, error) + ClrR(context.Context, []byte, []byte, uint64) ([]KV, error) - Get(int64, []byte) (KV, error) - GetP(int64, []byte, uint64) ([]KV, error) - GetR(int64, []byte, []byte, uint64) ([]KV, error) + Get(context.Context, int64, []byte) (KV, error) + GetP(context.Context, int64, []byte, uint64) ([]KV, error) + GetR(context.Context, int64, []byte, []byte, uint64) ([]KV, error) - Del(int64, []byte) (KV, error) - DelC(int64, []byte, []byte) (KV, error) - DelP(int64, []byte, uint64) ([]KV, error) - DelR(int64, []byte, []byte, uint64) ([]KV, error) + Del(context.Context, int64, []byte) (KV, error) + DelC(context.Context, int64, []byte, []byte) (KV, error) + DelP(context.Context, int64, []byte, uint64) ([]KV, error) + DelR(context.Context, int64, []byte, []byte, uint64) ([]KV, error) - Put(int64, []byte, []byte) (KV, error) - PutC(int64, []byte, []byte, []byte) (KV, error) + Put(context.Context, int64, []byte, []byte) (KV, error) + PutC(context.Context, int64, []byte, []byte, []byte) (KV, error) } diff --git a/mem/mem.go b/mem/mem.go index 69414891..d7ded929 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -17,6 +17,8 @@ package mem import ( "sync" + "context" + "github.com/abcum/surreal/cnf" "github.com/abcum/surreal/kvs" "github.com/abcum/surreal/sql" @@ -72,7 +74,7 @@ func (c *Cache) del(key keys.Key) { // -------------------------------------------------- -func (c *Cache) AllNS() (out []*sql.DefineNamespaceStatement, err error) { +func (c *Cache) AllNS(ctx context.Context) (out []*sql.DefineNamespaceStatement, err error) { var kvs []kvs.KV @@ -85,7 +87,7 @@ func (c *Cache) AllNS() (out []*sql.DefineNamespaceStatement, err error) { return out.([]*sql.DefineNamespaceStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -101,7 +103,7 @@ func (c *Cache) AllNS() (out []*sql.DefineNamespaceStatement, err error) { } -func (c *Cache) GetNS(ns string) (val *sql.DefineNamespaceStatement, err error) { +func (c *Cache) GetNS(ctx context.Context, ns string) (val *sql.DefineNamespaceStatement, err error) { var kv kvs.KV @@ -114,7 +116,7 @@ func (c *Cache) GetNS(ns string) (val *sql.DefineNamespaceStatement, err error) return out.(*sql.DefineNamespaceStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -131,7 +133,7 @@ func (c *Cache) GetNS(ns string) (val *sql.DefineNamespaceStatement, err error) } -func (c *Cache) AddNS(ns string) (val *sql.DefineNamespaceStatement, err error) { +func (c *Cache) AddNS(ctx context.Context, ns string) (val *sql.DefineNamespaceStatement, err error) { var kv kvs.KV @@ -144,7 +146,7 @@ func (c *Cache) AddNS(ns string) (val *sql.DefineNamespaceStatement, err error) return out.(*sql.DefineNamespaceStatement), nil } - if kv, _ = c.TX.Get(0, key.Encode()); kv.Exi() { + if kv, _ = c.TX.Get(ctx, 0, key.Encode()); kv.Exi() { val = &sql.DefineNamespaceStatement{} val.Decode(kv.Val()) c.put(key, val) @@ -152,7 +154,7 @@ func (c *Cache) AddNS(ns string) (val *sql.DefineNamespaceStatement, err error) } val = &sql.DefineNamespaceStatement{Name: sql.NewIdent(ns)} - c.TX.PutC(0, key.Encode(), val.Encode(), nil) + c.TX.PutC(ctx, 0, key.Encode(), val.Encode(), nil) c.put(key, val) @@ -170,12 +172,12 @@ func (c *Cache) DelNS(ns string) { // -------------------------------------------------- -func (c *Cache) AllNT(ns string) (out []*sql.DefineTokenStatement, err error) { +func (c *Cache) AllNT(ctx context.Context, ns string) (out []*sql.DefineTokenStatement, err error) { var kvs []kvs.KV key := &keys.NT{KV: cnf.Settings.DB.Base, NS: ns, TK: keys.Ignore} - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -189,12 +191,12 @@ func (c *Cache) AllNT(ns string) (out []*sql.DefineTokenStatement, err error) { } -func (c *Cache) GetNT(ns, tk string) (val *sql.DefineTokenStatement, err error) { +func (c *Cache) GetNT(ctx context.Context, ns, tk string) (val *sql.DefineTokenStatement, err error) { var kv kvs.KV key := &keys.NT{KV: cnf.Settings.DB.Base, NS: ns, TK: tk} - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -211,12 +213,12 @@ func (c *Cache) GetNT(ns, tk string) (val *sql.DefineTokenStatement, err error) // -------------------------------------------------- -func (c *Cache) AllNU(ns string) (out []*sql.DefineLoginStatement, err error) { +func (c *Cache) AllNU(ctx context.Context, ns string) (out []*sql.DefineLoginStatement, err error) { var kvs []kvs.KV key := &keys.NU{KV: cnf.Settings.DB.Base, NS: ns, US: keys.Ignore} - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -230,12 +232,12 @@ func (c *Cache) AllNU(ns string) (out []*sql.DefineLoginStatement, err error) { } -func (c *Cache) GetNU(ns, us string) (val *sql.DefineLoginStatement, err error) { +func (c *Cache) GetNU(ctx context.Context, ns, us string) (val *sql.DefineLoginStatement, err error) { var kv kvs.KV key := &keys.NU{KV: cnf.Settings.DB.Base, NS: ns, US: us} - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -252,7 +254,7 @@ func (c *Cache) GetNU(ns, us string) (val *sql.DefineLoginStatement, err error) // -------------------------------------------------- -func (c *Cache) AllDB(ns string) (out []*sql.DefineDatabaseStatement, err error) { +func (c *Cache) AllDB(ctx context.Context, ns string) (out []*sql.DefineDatabaseStatement, err error) { var kvs []kvs.KV @@ -265,7 +267,7 @@ func (c *Cache) AllDB(ns string) (out []*sql.DefineDatabaseStatement, err error) return out.([]*sql.DefineDatabaseStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -281,7 +283,7 @@ func (c *Cache) AllDB(ns string) (out []*sql.DefineDatabaseStatement, err error) } -func (c *Cache) GetDB(ns, db string) (val *sql.DefineDatabaseStatement, err error) { +func (c *Cache) GetDB(ctx context.Context, ns, db string) (val *sql.DefineDatabaseStatement, err error) { var kv kvs.KV @@ -294,7 +296,7 @@ func (c *Cache) GetDB(ns, db string) (val *sql.DefineDatabaseStatement, err erro return out.(*sql.DefineDatabaseStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -311,9 +313,9 @@ func (c *Cache) GetDB(ns, db string) (val *sql.DefineDatabaseStatement, err erro } -func (c *Cache) AddDB(ns, db string) (val *sql.DefineDatabaseStatement, err error) { +func (c *Cache) AddDB(ctx context.Context, ns, db string) (val *sql.DefineDatabaseStatement, err error) { - if _, err = c.AddNS(ns); err != nil { + if _, err = c.AddNS(ctx, ns); err != nil { return } @@ -328,7 +330,7 @@ func (c *Cache) AddDB(ns, db string) (val *sql.DefineDatabaseStatement, err erro return out.(*sql.DefineDatabaseStatement), nil } - if kv, _ = c.TX.Get(0, key.Encode()); kv.Exi() { + if kv, _ = c.TX.Get(ctx, 0, key.Encode()); kv.Exi() { val = &sql.DefineDatabaseStatement{} val.Decode(kv.Val()) c.put(key, val) @@ -336,7 +338,7 @@ func (c *Cache) AddDB(ns, db string) (val *sql.DefineDatabaseStatement, err erro } val = &sql.DefineDatabaseStatement{Name: sql.NewIdent(db)} - c.TX.PutC(0, key.Encode(), val.Encode(), nil) + c.TX.PutC(ctx, 0, key.Encode(), val.Encode(), nil) c.put(key, val) @@ -354,12 +356,12 @@ func (c *Cache) DelDB(ns, db string) { // -------------------------------------------------- -func (c *Cache) AllDT(ns, db string) (out []*sql.DefineTokenStatement, err error) { +func (c *Cache) AllDT(ctx context.Context, ns, db string) (out []*sql.DefineTokenStatement, err error) { var kvs []kvs.KV key := &keys.DT{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TK: keys.Ignore} - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -373,12 +375,12 @@ func (c *Cache) AllDT(ns, db string) (out []*sql.DefineTokenStatement, err error } -func (c *Cache) GetDT(ns, db, tk string) (val *sql.DefineTokenStatement, err error) { +func (c *Cache) GetDT(ctx context.Context, ns, db, tk string) (val *sql.DefineTokenStatement, err error) { var kv kvs.KV key := &keys.DT{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TK: tk} - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -395,12 +397,12 @@ func (c *Cache) GetDT(ns, db, tk string) (val *sql.DefineTokenStatement, err err // -------------------------------------------------- -func (c *Cache) AllDU(ns, db string) (out []*sql.DefineLoginStatement, err error) { +func (c *Cache) AllDU(ctx context.Context, ns, db string) (out []*sql.DefineLoginStatement, err error) { var kvs []kvs.KV key := &keys.DU{KV: cnf.Settings.DB.Base, NS: ns, DB: db, US: keys.Ignore} - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -414,12 +416,12 @@ func (c *Cache) AllDU(ns, db string) (out []*sql.DefineLoginStatement, err error } -func (c *Cache) GetDU(ns, db, us string) (val *sql.DefineLoginStatement, err error) { +func (c *Cache) GetDU(ctx context.Context, ns, db, us string) (val *sql.DefineLoginStatement, err error) { var kv kvs.KV key := &keys.DU{KV: cnf.Settings.DB.Base, NS: ns, DB: db, US: us} - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -436,12 +438,12 @@ func (c *Cache) GetDU(ns, db, us string) (val *sql.DefineLoginStatement, err err // -------------------------------------------------- -func (c *Cache) AllSC(ns, db string) (out []*sql.DefineScopeStatement, err error) { +func (c *Cache) AllSC(ctx context.Context, ns, db string) (out []*sql.DefineScopeStatement, err error) { var kvs []kvs.KV key := &keys.SC{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: keys.Ignore} - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -455,12 +457,12 @@ func (c *Cache) AllSC(ns, db string) (out []*sql.DefineScopeStatement, err error } -func (c *Cache) GetSC(ns, db, sc string) (val *sql.DefineScopeStatement, err error) { +func (c *Cache) GetSC(ctx context.Context, ns, db, sc string) (val *sql.DefineScopeStatement, err error) { var kv kvs.KV key := &keys.SC{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: sc} - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -477,12 +479,12 @@ func (c *Cache) GetSC(ns, db, sc string) (val *sql.DefineScopeStatement, err err // -------------------------------------------------- -func (c *Cache) AllST(ns, db, sc string) (out []*sql.DefineTokenStatement, err error) { +func (c *Cache) AllST(ctx context.Context, ns, db, sc string) (out []*sql.DefineTokenStatement, err error) { var kvs []kvs.KV key := &keys.ST{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: sc, TK: keys.Ignore} - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -496,12 +498,12 @@ func (c *Cache) AllST(ns, db, sc string) (out []*sql.DefineTokenStatement, err e } -func (c *Cache) GetST(ns, db, sc, tk string) (val *sql.DefineTokenStatement, err error) { +func (c *Cache) GetST(ctx context.Context, ns, db, sc, tk string) (val *sql.DefineTokenStatement, err error) { var kv kvs.KV key := &keys.ST{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: sc, TK: tk} - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -518,7 +520,7 @@ func (c *Cache) GetST(ns, db, sc, tk string) (val *sql.DefineTokenStatement, err // -------------------------------------------------- -func (c *Cache) AllTB(ns, db string) (out []*sql.DefineTableStatement, err error) { +func (c *Cache) AllTB(ctx context.Context, ns, db string) (out []*sql.DefineTableStatement, err error) { var kvs []kvs.KV @@ -531,7 +533,7 @@ func (c *Cache) AllTB(ns, db string) (out []*sql.DefineTableStatement, err error return out.([]*sql.DefineTableStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -547,7 +549,7 @@ func (c *Cache) AllTB(ns, db string) (out []*sql.DefineTableStatement, err error } -func (c *Cache) GetTB(ns, db, tb string) (val *sql.DefineTableStatement, err error) { +func (c *Cache) GetTB(ctx context.Context, ns, db, tb string) (val *sql.DefineTableStatement, err error) { var kv kvs.KV @@ -560,7 +562,7 @@ func (c *Cache) GetTB(ns, db, tb string) (val *sql.DefineTableStatement, err err return out.(*sql.DefineTableStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -577,9 +579,9 @@ func (c *Cache) GetTB(ns, db, tb string) (val *sql.DefineTableStatement, err err } -func (c *Cache) AddTB(ns, db, tb string) (val *sql.DefineTableStatement, err error) { +func (c *Cache) AddTB(ctx context.Context, ns, db, tb string) (val *sql.DefineTableStatement, err error) { - if _, err = c.AddDB(ns, db); err != nil { + if _, err = c.AddDB(ctx, ns, db); err != nil { return } @@ -594,7 +596,7 @@ func (c *Cache) AddTB(ns, db, tb string) (val *sql.DefineTableStatement, err err return out.(*sql.DefineTableStatement), nil } - if kv, _ = c.TX.Get(0, key.Encode()); kv.Exi() { + if kv, _ = c.TX.Get(ctx, 0, key.Encode()); kv.Exi() { val = &sql.DefineTableStatement{} val.Decode(kv.Val()) c.put(key, val) @@ -602,7 +604,7 @@ func (c *Cache) AddTB(ns, db, tb string) (val *sql.DefineTableStatement, err err } val = &sql.DefineTableStatement{Name: sql.NewIdent(tb)} - c.TX.PutC(0, key.Encode(), val.Encode(), nil) + c.TX.PutC(ctx, 0, key.Encode(), val.Encode(), nil) c.put(key, val) @@ -620,7 +622,7 @@ func (c *Cache) DelTB(ns, db, tb string) { // -------------------------------------------------- -func (c *Cache) AllEV(ns, db, tb string) (out []*sql.DefineEventStatement, err error) { +func (c *Cache) AllEV(ctx context.Context, ns, db, tb string) (out []*sql.DefineEventStatement, err error) { var kvs []kvs.KV @@ -630,7 +632,7 @@ func (c *Cache) AllEV(ns, db, tb string) (out []*sql.DefineEventStatement, err e return out.([]*sql.DefineEventStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -646,7 +648,7 @@ func (c *Cache) AllEV(ns, db, tb string) (out []*sql.DefineEventStatement, err e } -func (c *Cache) GetEV(ns, db, tb, ev string) (val *sql.DefineEventStatement, err error) { +func (c *Cache) GetEV(ctx context.Context, ns, db, tb, ev string) (val *sql.DefineEventStatement, err error) { var kv kvs.KV @@ -656,7 +658,7 @@ func (c *Cache) GetEV(ns, db, tb, ev string) (val *sql.DefineEventStatement, err return out.(*sql.DefineEventStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -683,7 +685,7 @@ func (c *Cache) DelEV(ns, db, tb, ev string) { // -------------------------------------------------- -func (c *Cache) AllFD(ns, db, tb string) (out []*sql.DefineFieldStatement, err error) { +func (c *Cache) AllFD(ctx context.Context, ns, db, tb string) (out []*sql.DefineFieldStatement, err error) { var kvs []kvs.KV @@ -693,7 +695,7 @@ func (c *Cache) AllFD(ns, db, tb string) (out []*sql.DefineFieldStatement, err e return out.([]*sql.DefineFieldStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -709,7 +711,7 @@ func (c *Cache) AllFD(ns, db, tb string) (out []*sql.DefineFieldStatement, err e } -func (c *Cache) GetFD(ns, db, tb, fd string) (val *sql.DefineFieldStatement, err error) { +func (c *Cache) GetFD(ctx context.Context, ns, db, tb, fd string) (val *sql.DefineFieldStatement, err error) { var kv kvs.KV @@ -719,7 +721,7 @@ func (c *Cache) GetFD(ns, db, tb, fd string) (val *sql.DefineFieldStatement, err return out.(*sql.DefineFieldStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -746,7 +748,7 @@ func (c *Cache) DelFD(ns, db, tb, fd string) { // -------------------------------------------------- -func (c *Cache) AllIX(ns, db, tb string) (out []*sql.DefineIndexStatement, err error) { +func (c *Cache) AllIX(ctx context.Context, ns, db, tb string) (out []*sql.DefineIndexStatement, err error) { var kvs []kvs.KV @@ -756,7 +758,7 @@ func (c *Cache) AllIX(ns, db, tb string) (out []*sql.DefineIndexStatement, err e return out.([]*sql.DefineIndexStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -772,7 +774,7 @@ func (c *Cache) AllIX(ns, db, tb string) (out []*sql.DefineIndexStatement, err e } -func (c *Cache) GetIX(ns, db, tb, ix string) (val *sql.DefineIndexStatement, err error) { +func (c *Cache) GetIX(ctx context.Context, ns, db, tb, ix string) (val *sql.DefineIndexStatement, err error) { var kv kvs.KV @@ -782,7 +784,7 @@ func (c *Cache) GetIX(ns, db, tb, ix string) (val *sql.DefineIndexStatement, err return out.(*sql.DefineIndexStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -809,7 +811,7 @@ func (c *Cache) DelIX(ns, db, tb, ix string) { // -------------------------------------------------- -func (c *Cache) AllFT(ns, db, tb string) (out []*sql.DefineTableStatement, err error) { +func (c *Cache) AllFT(ctx context.Context, ns, db, tb string) (out []*sql.DefineTableStatement, err error) { var kvs []kvs.KV @@ -819,7 +821,7 @@ func (c *Cache) AllFT(ns, db, tb string) (out []*sql.DefineTableStatement, err e return out.([]*sql.DefineTableStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -835,7 +837,7 @@ func (c *Cache) AllFT(ns, db, tb string) (out []*sql.DefineTableStatement, err e } -func (c *Cache) GetFT(ns, db, tb, ft string) (val *sql.DefineTableStatement, err error) { +func (c *Cache) GetFT(ctx context.Context, ns, db, tb, ft string) (val *sql.DefineTableStatement, err error) { var kv kvs.KV @@ -845,7 +847,7 @@ func (c *Cache) GetFT(ns, db, tb, ft string) (val *sql.DefineTableStatement, err return out.(*sql.DefineTableStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } @@ -872,7 +874,7 @@ func (c *Cache) DelFT(ns, db, tb, ft string) { // -------------------------------------------------- -func (c *Cache) AllLV(ns, db, tb string) (out []*sql.LiveStatement, err error) { +func (c *Cache) AllLV(ctx context.Context, ns, db, tb string) (out []*sql.LiveStatement, err error) { var kvs []kvs.KV @@ -882,7 +884,7 @@ func (c *Cache) AllLV(ns, db, tb string) (out []*sql.LiveStatement, err error) { return out.([]*sql.LiveStatement), nil } - if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil { + if kvs, err = c.TX.GetP(ctx, 0, key.Encode(), 0); err != nil { return } @@ -898,7 +900,7 @@ func (c *Cache) AllLV(ns, db, tb string) (out []*sql.LiveStatement, err error) { } -func (c *Cache) GetLV(ns, db, tb, lv string) (val *sql.LiveStatement, err error) { +func (c *Cache) GetLV(ctx context.Context, ns, db, tb, lv string) (val *sql.LiveStatement, err error) { var kv kvs.KV @@ -908,7 +910,7 @@ func (c *Cache) GetLV(ns, db, tb, lv string) (val *sql.LiveStatement, err error) return out.(*sql.LiveStatement), nil } - if kv, err = c.TX.Get(0, key.Encode()); err != nil { + if kv, err = c.TX.Get(ctx, 0, key.Encode()); err != nil { return nil, err } diff --git a/web/auth.go b/web/auth.go index db9c2f54..d686718e 100644 --- a/web/auth.go +++ b/web/auth.go @@ -248,7 +248,7 @@ func checkBasics(c *fibre.Context, info string, callback func() error) (err erro u := string(cred[0]) p := string(cred[1]) - if _, err = signinNS(n, u, p); err == nil { + if _, err = signinNS(c, n, u, p); err == nil { auth.Kind = cnf.AuthNS auth.Possible.NS = n auth.Possible.DB = "*" @@ -264,7 +264,7 @@ func checkBasics(c *fibre.Context, info string, callback func() error) (err erro u := string(cred[0]) p := string(cred[1]) - if _, err = signinDB(n, d, u, p); err == nil { + if _, err = signinDB(c, n, d, u, p); err == nil { auth.Kind = cnf.AuthDB auth.Possible.NS = n auth.Possible.DB = d @@ -297,6 +297,10 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro defer txn.Cancel() + // Get the current context. + + ctx := c.Context() + // Setup the kvs layer cache. cache := mem.NewWithTX(txn) @@ -331,7 +335,7 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro if nsk && dbk && sck && tkk { - scp, err := cache.GetSC(nsv, dbv, scv) + scp, err := cache.GetSC(ctx, nsv, dbv, scv) if err != nil { return nil, fmt.Errorf("Credentials failed") } @@ -377,7 +381,7 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro } if tkv != "default" { - key, err := cache.GetST(nsv, dbv, scv, tkv) + key, err := cache.GetST(ctx, nsv, dbv, scv, tkv) if err != nil { return nil, fmt.Errorf("Credentials failed") } @@ -394,7 +398,7 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro } else if nsk && dbk && tkk { if tkv != "default" { - key, err := cache.GetDT(nsv, dbv, tkv) + key, err := cache.GetDT(ctx, nsv, dbv, tkv) if err != nil { return nil, fmt.Errorf("Credentials failed") } @@ -404,7 +408,7 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro auth.Kind = cnf.AuthDB return key.Code, nil } else if usk { - usr, err := cache.GetDU(nsv, dbv, usv) + usr, err := cache.GetDU(ctx, nsv, dbv, usv) if err != nil { return nil, fmt.Errorf("Credentials failed") } @@ -415,7 +419,7 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro } else if nsk && tkk { if tkv != "default" { - key, err := cache.GetNT(nsv, tkv) + key, err := cache.GetNT(ctx, nsv, tkv) if err != nil { return nil, fmt.Errorf("Credentials failed") } @@ -425,7 +429,7 @@ func checkBearer(c *fibre.Context, info string, callback func() error) (err erro auth.Kind = cnf.AuthNS return key.Code, nil } else if usk { - usr, err := cache.GetNU(nsv, usv) + usr, err := cache.GetNU(ctx, nsv, usv) if err != nil { return nil, fmt.Errorf("Credentials failed") } diff --git a/web/signin.go b/web/signin.go index e718a688..5e092c50 100644 --- a/web/signin.go +++ b/web/signin.go @@ -93,6 +93,10 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string, defer txn.Cancel() + // Get the current context. + + ctx := c.Context() + // Give full permissions to scope. c.Set(varKeyAuth, &cnf.Auth{Kind: cnf.AuthDB}) @@ -103,7 +107,7 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string, // Get the specified signin scope. - if scp, err = mem.NewWithTX(txn).GetSC(n, d, s); err != nil { + if scp, err = mem.NewWithTX(txn).GetSC(ctx, n, d, s); err != nil { m := "Authentication scope does not exist" return str, fibre.NewHTTPError(403).WithFields(f).WithMessage(m) } @@ -233,7 +237,7 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string, // Start a new read transaction. - if usr, err = signinDB(n, d, u, p); err != nil { + if usr, err = signinDB(c, n, d, u, p); err != nil { return str, err } @@ -287,7 +291,7 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string, return str, fibre.NewHTTPError(403).WithFields(f).WithMessage(m) } - if usr, err = signinNS(n, u, p); err != nil { + if usr, err = signinNS(c, n, u, p); err != nil { return str, err } @@ -319,7 +323,7 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string, } -func signinDB(n, d, u, p string) (usr *sql.DefineLoginStatement, err error) { +func signinDB(c *fibre.Context, n, d, u, p string) (usr *sql.DefineLoginStatement, err error) { var txn kvs.TX @@ -333,6 +337,10 @@ func signinDB(n, d, u, p string) (usr *sql.DefineLoginStatement, err error) { defer txn.Cancel() + // Get the current context. + + ctx := c.Context() + // Specify fields to show in logs. f := map[string]interface{}{"ns": n, "db": d, "du": u} @@ -346,7 +354,7 @@ func signinDB(n, d, u, p string) (usr *sql.DefineLoginStatement, err error) { // Get the specified namespace login. - if usr, err = mem.NewWithTX(txn).GetDU(n, d, u); err != nil { + if usr, err = mem.NewWithTX(txn).GetDU(ctx, n, d, u); err != nil { m := "Database login does not exist" return nil, fibre.NewHTTPError(403).WithFields(f).WithMessage(m) } @@ -362,7 +370,7 @@ func signinDB(n, d, u, p string) (usr *sql.DefineLoginStatement, err error) { } -func signinNS(n, u, p string) (usr *sql.DefineLoginStatement, err error) { +func signinNS(c *fibre.Context, n, u, p string) (usr *sql.DefineLoginStatement, err error) { var txn kvs.TX @@ -376,6 +384,10 @@ func signinNS(n, u, p string) (usr *sql.DefineLoginStatement, err error) { defer txn.Cancel() + // Get the current context. + + ctx := c.Context() + // Specify fields to show in logs. f := map[string]interface{}{"ns": n, "nu": u} @@ -389,7 +401,7 @@ func signinNS(n, u, p string) (usr *sql.DefineLoginStatement, err error) { // Get the specified namespace login. - if usr, err = mem.NewWithTX(txn).GetNU(n, u); err != nil { + if usr, err = mem.NewWithTX(txn).GetNU(ctx, n, u); err != nil { m := "Namespace login does not exist" return nil, fibre.NewHTTPError(403).WithFields(f).WithMessage(m) } diff --git a/web/signup.go b/web/signup.go index f24976e4..f2b27df0 100644 --- a/web/signup.go +++ b/web/signup.go @@ -92,6 +92,10 @@ func signupInternal(c *fibre.Context, vars map[string]interface{}) (str string, defer txn.Cancel() + // Get the current context. + + ctx := c.Context() + // Give full permissions to scope. c.Set(varKeyAuth, &cnf.Auth{Kind: cnf.AuthDB}) @@ -102,7 +106,7 @@ func signupInternal(c *fibre.Context, vars map[string]interface{}) (str string, // Get the specified signin scope. - if scp, err = mem.NewWithTX(txn).GetSC(n, d, s); err != nil { + if scp, err = mem.NewWithTX(txn).GetSC(ctx, n, d, s); err != nil { m := "Authentication scope does not exist" return str, fibre.NewHTTPError(403).WithFields(f).WithMessage(m) }