|
|
// Code generated by sqlc. DO NOT EDIT.
// source: changes.sql
package psqlcore
import ( "context" "encoding/json" "time"
"github.com/lib/pq" )
const deleteChange = `-- name: DeleteChange :exec DELETE FROM data_change WHERE id = $1 `
func (q *Queries) DeleteChange(ctx context.Context, id string) error { _, err := q.db.ExecContext(ctx, deleteChange, id) return err }
const insertChange = `-- name: InsertChange :exec INSERT INTO data_change (id, model, op, author, listed, date, keys, objects) VALUES ( $1::text, $2::text, $3::text, $4::text, $5::boolean, $6::timestamp, $7::text[], $8::jsonb ) `
type InsertChangeParams struct { ID string `json:"id"` Model string `json:"model"` Op string `json:"op"` Author string `json:"author"` Listed bool `json:"listed"` Date time.Time `json:"date"` Keys []string `json:"keys"` Objects json.RawMessage `json:"objects"` }
func (q *Queries) InsertChange(ctx context.Context, arg InsertChangeParams) error { _, err := q.db.ExecContext(ctx, insertChange, arg.ID, arg.Model, arg.Op, arg.Author, arg.Listed, arg.Date, pq.Array(arg.Keys), arg.Objects, ) return err }
const selectChangeByID = `-- name: SelectChangeByID :one SELECT id, model, op, author, listed, date, keys, objects FROM data_change WHERE id = $1 LIMIT 1 `
func (q *Queries) SelectChangeByID(ctx context.Context, id string) (DataChange, error) { row := q.db.QueryRowContext(ctx, selectChangeByID, id) var i DataChange err := row.Scan( &i.ID, &i.Model, &i.Op, &i.Author, &i.Listed, &i.Date, pq.Array(&i.Keys), &i.Objects, ) return i, err }
const selectChanges = `-- name: SelectChanges :many SELECT id, model, op, author, listed, date, keys, objects FROM data_change WHERE ($1::bool = false OR keys && ($2::text[])) AND ($3::bool = false OR date >= $4::timestamp) AND ($5::bool = false OR date <= $6::timestamp) AND ($7::bool = false OR author = $8::text) LIMIT $9::int `
type SelectChangesParams struct { FilterKeys bool `json:"filter_keys"` Keys []string `json:"keys"` FilterEarliestDate bool `json:"filter_earliest_date"` EarliestDate time.Time `json:"earliest_date"` FilterLatestDate bool `json:"filter_latest_date"` LatestDate time.Time `json:"latest_date"` FilterAuthor bool `json:"filter_author"` Author string `json:"author"` LimitSize int32 `json:"limit_size"` }
func (q *Queries) SelectChanges(ctx context.Context, arg SelectChangesParams) ([]DataChange, error) { rows, err := q.db.QueryContext(ctx, selectChanges, arg.FilterKeys, pq.Array(arg.Keys), arg.FilterEarliestDate, arg.EarliestDate, arg.FilterLatestDate, arg.LatestDate, arg.FilterAuthor, arg.Author, arg.LimitSize, ) if err != nil { return nil, err } defer rows.Close() items := []DataChange{} for rows.Next() { var i DataChange if err := rows.Scan( &i.ID, &i.Model, &i.Op, &i.Author, &i.Listed, &i.Date, pq.Array(&i.Keys), &i.Objects, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil }
|