This in a pretty huge change. At a high level we're adding the concept of a 'contact' which is a person or organization that has zero or more contact methods (email, phone). This ended up cascading a number of changes, including critically to the publicreprt schema. In the end it seemed safer to get to the point where I'm confident we aren't using any of the old fields for storing reporter information (though I haven't deleted the columns yet) so I removed the code for defining those columns. At this point I think it's not possible for me to regenerate the bob schema due to the interdependencies between my various schemas, so the migration is well-and-truly happening.
47 lines
1.6 KiB
Go
47 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)
|
|
}
|
|
*/
|