Connect the remaining record svc CRUD operations to DAL
This commit is contained in:
@@ -536,7 +536,7 @@ func (svc record) create(ctx context.Context, new *types.Record) (rec *types.Rec
|
||||
return nil, RecordErrValueInput().Wrap(rve)
|
||||
}
|
||||
|
||||
err = svc.dal.Create(ctx, m.ModelFilter(), svc.recCreateCapabilities(m), svc.recToGetter(new)...)
|
||||
err = svc.dal.Create(ctx, m.ModelFilter(), svc.recCreateCapabilities(m), svc.recToGetters(new)...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -793,7 +793,7 @@ func (svc record) update(ctx context.Context, upd *types.Record) (rec *types.Rec
|
||||
}
|
||||
}
|
||||
|
||||
return store.UpdateComposeRecord(ctx, s, m, upd)
|
||||
return svc.dal.Update(ctx, m.ModelFilter(), svc.recUpdateCapabilities(m), svc.recToGetter(upd))
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -982,10 +982,7 @@ func (svc record) delete(ctx context.Context, namespaceID, moduleID, recordID ui
|
||||
del.DeletedAt = now()
|
||||
del.DeletedBy = invokerID
|
||||
|
||||
err = store.Tx(ctx, svc.store, func(ctx context.Context, s store.Storer) error {
|
||||
return store.UpdateComposeRecord(ctx, s, m, del)
|
||||
})
|
||||
|
||||
err = svc.dal.Update(ctx, m.ModelFilter(), svc.recDeleteCapabilities(m), del)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -12,8 +12,11 @@ import (
|
||||
type (
|
||||
dalDML interface {
|
||||
Create(ctx context.Context, m dal.ModelFilter, capabilities capabilities.Set, vv ...dal.ValueGetter) error
|
||||
Update(ctx context.Context, m dal.ModelFilter, capabilities capabilities.Set, r dal.ValueGetter) (err error)
|
||||
Search(ctx context.Context, m dal.ModelFilter, capabilities capabilities.Set, f filter.Filter) (dal.Iterator, error)
|
||||
Lookup(ctx context.Context, m dal.ModelFilter, capabilities capabilities.Set, lookup dal.ValueGetter, dst dal.ValueSetter) (err error)
|
||||
Delete(ctx context.Context, m dal.ModelFilter, capabilities capabilities.Set, pkv dal.ValueGetter) (err error)
|
||||
Truncate(ctx context.Context, m dal.ModelFilter, capabilities capabilities.Set) (err error)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -64,7 +67,7 @@ func (svc *record) prepareRecordTarget(module *types.Module) *types.Record {
|
||||
}
|
||||
}
|
||||
|
||||
func (svc *record) recToGetter(rr ...*types.Record) (out []dal.ValueGetter) {
|
||||
func (svc *record) recToGetters(rr ...*types.Record) (out []dal.ValueGetter) {
|
||||
out = make([]dal.ValueGetter, len(rr))
|
||||
|
||||
for i := range rr {
|
||||
@@ -74,12 +77,26 @@ func (svc *record) recToGetter(rr ...*types.Record) (out []dal.ValueGetter) {
|
||||
return
|
||||
}
|
||||
|
||||
// recCreateCapabilities utility helps construct required creation capabilities
|
||||
func (svc *record) recToGetter(rr ...*types.Record) (out dal.ValueGetter) {
|
||||
if len(rr) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
return svc.recToGetters(rr...)[0]
|
||||
}
|
||||
|
||||
func (svc *record) recCreateCapabilities(m *types.Module) (out capabilities.Set) {
|
||||
return capabilities.CreateCapabilities(m.DALConfig.Capabilities...)
|
||||
}
|
||||
|
||||
// recFilterCapabilities utility helps construct required filter capabilities based on the provided record filter
|
||||
func (svc *record) recUpdateCapabilities(m *types.Module) (out capabilities.Set) {
|
||||
return capabilities.UpdateCapabilities(m.DALConfig.Capabilities...)
|
||||
}
|
||||
|
||||
func (svc *record) recDeleteCapabilities(m *types.Module) (out capabilities.Set) {
|
||||
return capabilities.DeleteCapabilities(m.DALConfig.Capabilities...)
|
||||
}
|
||||
|
||||
func (svc *record) recFilterCapabilities(f types.RecordFilter) (out capabilities.Set) {
|
||||
if f.PageCursor != nil {
|
||||
out = append(out, capabilities.Paging)
|
||||
|
||||
+8
-3
@@ -36,9 +36,8 @@ type (
|
||||
// Create stores the given data into the underlying database
|
||||
Create(ctx context.Context, m *Model, rr ...ValueGetter) error
|
||||
|
||||
// Update(ctx context.Context, m *data.Model, rr ...ValueGetter) error
|
||||
// Delete(ctx context.Context, m *data.Model, rr ...ValueGetter) error
|
||||
// Truncate(ctx context.Context, m *data.Model) error
|
||||
// Update updates the given value in the underlying connection
|
||||
Update(ctx context.Context, m *Model, r ValueGetter) error
|
||||
|
||||
// Lookup returns one bit of data
|
||||
Lookup(context.Context, *Model, ValueGetter, ValueSetter) error
|
||||
@@ -46,6 +45,12 @@ type (
|
||||
// Search returns an iterator which can be used to access all if the bits
|
||||
Search(context.Context, *Model, filter.Filter) (Iterator, error)
|
||||
|
||||
// Delete deletes the given value
|
||||
Delete(ctx context.Context, m *Model, pkv ValueGetter) error
|
||||
|
||||
// Truncate deletes all the data for the given model
|
||||
Truncate(ctx context.Context, m *Model) error
|
||||
|
||||
// DDL stuff
|
||||
|
||||
// // returns all attribute types that driver supports
|
||||
|
||||
@@ -140,6 +140,15 @@ func (svc *service) Create(ctx context.Context, mf ModelFilter, capabilities cap
|
||||
return cw.connection.Create(ctx, model, rr...)
|
||||
}
|
||||
|
||||
func (svc *service) Update(ctx context.Context, mf ModelFilter, capabilities capabilities.Set, r ValueGetter) (err error) {
|
||||
model, cw, err := svc.storeOpPrep(ctx, mf, capabilities)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return cw.connection.Update(ctx, model, r)
|
||||
}
|
||||
|
||||
func (svc *service) Search(ctx context.Context, mf ModelFilter, capabilities capabilities.Set, f filter.Filter) (iter Iterator, err error) {
|
||||
model, cw, err := svc.storeOpPrep(ctx, mf, capabilities)
|
||||
if err != nil {
|
||||
@@ -157,6 +166,23 @@ func (svc *service) Lookup(ctx context.Context, mf ModelFilter, capabilities cap
|
||||
return cw.connection.Lookup(ctx, model, lookup, dst)
|
||||
}
|
||||
|
||||
func (svc *service) Delete(ctx context.Context, mf ModelFilter, capabilities capabilities.Set, pkv ValueGetter) (err error) {
|
||||
model, cw, err := svc.storeOpPrep(ctx, mf, capabilities)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return cw.connection.Delete(ctx, model, pkv)
|
||||
}
|
||||
func (svc *service) Truncate(ctx context.Context, mf ModelFilter, capabilities capabilities.Set) (err error) {
|
||||
model, cw, err := svc.storeOpPrep(ctx, mf, capabilities)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return cw.connection.Truncate(ctx, model)
|
||||
}
|
||||
|
||||
func (svc *service) storeOpPrep(ctx context.Context, mf ModelFilter, capabilities capabilities.Set) (model *Model, cw *connectionWrap, err error) {
|
||||
model = svc.getModelByFilter(mf)
|
||||
if model == nil {
|
||||
|
||||
@@ -57,6 +57,10 @@ func (c *connection) Create(ctx context.Context, m *dal.Model, rr ...dal.ValueGe
|
||||
return c.model(m).Create(ctx, rr...)
|
||||
}
|
||||
|
||||
func (c *connection) Update(ctx context.Context, m *dal.Model, r dal.ValueGetter) error {
|
||||
return c.model(m).Update(ctx, r)
|
||||
}
|
||||
|
||||
func (c *connection) Lookup(ctx context.Context, m *dal.Model, pkv dal.ValueGetter, r dal.ValueSetter) error {
|
||||
return c.model(m).Lookup(ctx, pkv, r)
|
||||
}
|
||||
@@ -65,6 +69,14 @@ func (c *connection) Search(ctx context.Context, m *dal.Model, f filter.Filter)
|
||||
return c.model(m).Search(f)
|
||||
}
|
||||
|
||||
func (c *connection) Delete(ctx context.Context, m *dal.Model, pkv dal.ValueGetter) error {
|
||||
return c.model(m).Delete(ctx, pkv)
|
||||
}
|
||||
|
||||
func (c *connection) Truncate(ctx context.Context, m *dal.Model) error {
|
||||
return c.model(m).Truncate(ctx)
|
||||
}
|
||||
|
||||
func (c *connection) Models(ctx context.Context) (dal.ModelSet, error) {
|
||||
//TODO implement me
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user