48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
|
|
package comms
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
//"github.com/Gleipnir-Technology/bob"
|
||
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||
|
|
//"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/enum"
|
||
|
|
"github.com/Gleipnir-Technology/jet/postgres"
|
||
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
|
||
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
|
||
|
|
)
|
||
|
|
|
||
|
|
func ContactInsert(ctx context.Context, txn db.Ex, m model.Contact) (model.Contact, error) {
|
||
|
|
statement := table.Contact.INSERT(table.Contact.MutableColumns).
|
||
|
|
MODEL(m).
|
||
|
|
RETURNING(table.Contact.AllColumns)
|
||
|
|
return db.ExecuteOneTx[model.Contact](ctx, txn, statement)
|
||
|
|
}
|
||
|
|
|
||
|
|
func ContactFromID(ctx context.Context, txn db.Ex, id int64) (model.Contact, error) {
|
||
|
|
statement := table.Contact.SELECT(
|
||
|
|
table.Contact.AllColumns,
|
||
|
|
).FROM(table.Contact).
|
||
|
|
WHERE(table.Contact.ID.EQ(postgres.Int(id)))
|
||
|
|
return db.ExecuteOne[model.Contact](ctx, statement)
|
||
|
|
}
|
||
|
|
|
||
|
|
func ContactUpdateName(ctx context.Context, txn db.Ex, id int64, name string) error {
|
||
|
|
statement := table.Contact.UPDATE().
|
||
|
|
SET(
|
||
|
|
table.Contact.Name.SET(postgres.String(name)),
|
||
|
|
).
|
||
|
|
WHERE(table.Contact.OrganizationID.EQ(postgres.Int(id)))
|
||
|
|
return db.ExecuteNoneTx(ctx, txn, statement)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
func ContactsFromAddress(ctx context.Context, address string) ([]model.Contact, error) {
|
||
|
|
statement := table.Contact.SELECT(
|
||
|
|
table.Contact.AllColumns,
|
||
|
|
).FROM(table.Contact).
|
||
|
|
WHERE(table.Contact.Source.EQ(postgres.String(address)).OR(
|
||
|
|
table.Contact.Destination.EQ(postgres.String(address))))
|
||
|
|
return db.ExecuteMany[model.Contact](ctx, statement)
|
||
|
|
}
|
||
|
|
*/
|