Documentation ¶
Index ¶
- Constants
- Variables
- func Add(x, y int) int
- func Error(err error) error
- func JoinSorter(cols []db.Sorter, fallback string) string
- func NewStore(DB *sql.DB) *db.Store
- func Open(uri string) (*db.Store, error)
- func Tx[T any](ctx context.Context, sqldb *sql.DB, callback func(*sql.Tx) (T, error)) (t T, err error)
- type MemberCollection
- func (colln MemberCollection) DeleteOne(ctx context.Context, id *db.MemberId) error
- func (colln MemberCollection) Find(ctx context.Context, filter *db.MemberFilter, projector *db.Projector) (list *db.Iterable[db.Member], err error)
- func (colln MemberCollection) FindOne(ctx context.Context, id *db.MemberId) (m db.Member, err error)
- func (colln MemberCollection) Insert(ctx context.Context, members ...db.Member) error
- func (colln MemberCollection) UpdateOne(context.Context, *db.MemberId, *db.MemberUpdater) error
- type ScountCollection
- func (colln ScountCollection) DeleteOne(ctx context.Context, id *db.ScountId) error
- func (colln ScountCollection) Find(ctx context.Context, filter *db.ScountFilter, projector *db.Projector) (list *db.Iterable[db.Scount], err error)
- func (colln ScountCollection) FindOne(ctx context.Context, id *db.ScountId) (s db.Scount, err error)
- func (colln ScountCollection) Insert(ctx context.Context, scounts ...db.Scount) error
- func (colln ScountCollection) UpdateOne(ctx context.Context, id *db.ScountId, setter *db.ScountUpdater) error
- type UserCollection
- func (colln UserCollection) DeleteOne(ctx context.Context, id *db.UserId) error
- func (colln UserCollection) Find(ctx context.Context, filter *db.UserFilter, projector *db.Projector) (list *db.Iterable[db.User], err error)
- func (colln UserCollection) FindByEmail(ctx context.Context, email string) (u db.User, err error)
- func (colln UserCollection) FindOne(ctx context.Context, id *db.UserId) (u db.User, err error)
- func (colln UserCollection) Insert(ctx context.Context, users ...db.User) error
- func (colln UserCollection) UpdateOne(ctx context.Context, id *db.UserId, setter *db.UserUpdater) error
- func (colln UserCollection) UpdatePassword(ctx context.Context, updater *db.PasswordUpdater) error
Constants ¶
const MemberDeleteQuery = `
DELETE FROM members
WHERE sid = $1 AND uid = $2;`
MemberDeleteQuery is a query statement for deleting single member by id.
const MemberInsertQuery = `
INSERT INTO members (sid, uid)
VALUES ($1, $2);`
MemberInsertQuery is query statement for inserting single member.
const MemberSelectQuery = `
SELECT sid, uid FROM members
WHERE sid = $1 AND uid = $2;`
MemberSelectQuery is a query statement for fetching single member by id.
const ScountDeleteQuery = `
DELETE FROM scounts
WHERE sid = $1;`
ScountDeleteQuery is a query statement for deleting a single scount by sid.
const ScountInsertQuery = `` /* 168-byte string literal not displayed */
ScountInsertQuery is a query statement for adding a single scount by id.
const ScountSelectQuery = `
SELECT sid, owner, title, description
FROM scounts
WHERE sid = $1;`
ScountSelectQuery is a query statement for fetching a single scount by sid.
const UserByEmailQuery = `
SELECT uid, email, username, password
FROM users
WHERE email = $1;`
UserByEmailQuery is a query statement for fetching single user by email.
const UserDeleteQuery = `
DELETE FROM users WHERE uid = $1;`
UserDeleteQuery is a query statement for deleting single user by uid.
const UserInsertQuery = `
INSERT INTO users (uid, email, username, password)
VALUES ($1, $2, $3, $4);`
UserInsertQuery is query statement for inserting single user.
const UserPasswordQuery = `
UPDATE users
SET password = $2
WHERE uid = $1 AND password = $3;`
UserPasswordQuery is a query statement for updating password of the user.
const UserSelectQuery = `
SELECT uid, email, username, password
FROM users
WHERE uid = $1;`
UserSelectQuery is a query statement for fetching single user by uid.
Variables ¶
var MemberSelectTemplate = template.Must(template.New("member-select"). Funcs(template.FuncMap{"join": JoinSorter}). Parse(` {{ define "filter" }} FROM members WHERE ($1 OR sid = $2) AND ($3 OR uid = $4) ORDER BY {{ join .Order "sid, uid" }} {{ end }} {{ define "find" }} SELECT sid, uid, {{ template "filter" }} {{ with .Paging }} LIMIT {{ .Limit }} OFFSET {{ .Offset }} {{ end }}; {{ end }} {{ define "count" }} SELECT count(*) AS total {{ template "filter" }}; {{ end }} `))
MemberSelectTemplate is a query template for finding matching members from MemberCollection.
var ScountSelectTemplate = template.Must(template.New("scount-select"). Funcs(template.FuncMap{"join": JoinSorter}). Parse(` {{ define "filter" }} FROM scounts NATURAL JOIN members WHERE ($1 OR sid = $2) AND ($3 OR uid = $4) AND ($5 OR owner = $6) AND ($7 OR title ILIKE $8) ORDER BY {{ join .Order "sid, uid" }} {{ end }} {{ define "find" }} SELECT DISTINCT sid, owner, title, description, {{ template "filter" }} {{ with .Paging }} LIMIT {{ .Limit }} OFFSET {{ .Offset }} {{ end }}; {{ end }} {{ define "count" }} SELECT count(*) AS total {{ template "filter" }}; {{ end }} `))
ScountSelectTemplate is a query template for finding scounts from ScountCollection.
var ScountUpdateTemplate = template.Must(template.New("scount-update"). Funcs(template.FuncMap{"add": Add}). Parse(` UPDATE scounts SET {{ range $i, $col := . }} {{ $col }} = {{ add $i 2 | printf "$%d" }} {{ end }} WHERE sid = $1; `))
ScountUpdateTemplate is a query template for updating scounts from ScountCollection.
var UserSelectTemplate = template.Must(template.New("user-select"). Funcs(template.FuncMap{"join": JoinSorter}). Parse(` {{ define "filter" }} FROM users WHERE ($1 OR uid = $2) AND ($3 OR email = $4) AND ($5 OR username ILIKE $6) {{ end }} {{ define "sort" }} ORDER BY {{ join .Order "uid" }} {{ end }} {{ define "find" }} SELECT DISTINCT uid, email, username, password {{ template "filter" }} {{ template "sort" }} {{ with .Paging }} LIMIT {{ .Limit }} OFFSET {{ .Offset }} {{ end }}; {{ end }} {{ define "count" }} SELECT count(*) AS total {{ template "filter" }} GROUP BY uid {{ template "sort" }}; {{ end }} `))
UserSelectTemplate is a query template for finding users from UserCollection.
var UserUpdateTemplate = template.Must(template.New("user-update"). Funcs(template.FuncMap{"add": Add}). Parse(` UPDATE users SET {{ range $i, $col := . }} {{ $col }} = {{ add $i 2 | printf "$%d" }} {{ end }} WHERE uid = $1; `))
UserUpdateTemplate is a query template for updating users from UserCollection.
Functions ¶
func JoinSorter ¶
JoinSorter defines `join` operation inside templates.
func NewStore ¶
NewStore constructs a db.Store from a SQL (postgres supported) database connection handle.
Types ¶
type MemberCollection ¶
MemberCollection provides a convenient way to interact with `members` table.
func (MemberCollection) DeleteOne ¶
DeleteOne removes exactly 1 member from `members` collection based on matching id.
func (MemberCollection) Find ¶
func (colln MemberCollection) Find( ctx context.Context, filter *db.MemberFilter, projector *db.Projector, ) (list *db.Iterable[db.Member], err error)
Find fetches all the members from colln subject to filter and projection options specified.
func (MemberCollection) FindOne ¶
func (colln MemberCollection) FindOne( ctx context.Context, id *db.MemberId, ) (m db.Member, err error)
FindOne fetches member from colln by id.
func (MemberCollection) Insert ¶
Insert adds one or more members to colln. db.ErrNoRows if no users to insert.
func (MemberCollection) UpdateOne ¶
func (colln MemberCollection) UpdateOne(context.Context, *db.MemberId, *db.MemberUpdater) error
UpdateOne is not supported on `members` collection.
type ScountCollection ¶
ScountCollection provides a convenient way to interact with `scounts` table.
func (ScountCollection) DeleteOne ¶
DeleteOne removes exactly 1 scount from `scounts` collection based on sid.
func (ScountCollection) Find ¶
func (colln ScountCollection) Find( ctx context.Context, filter *db.ScountFilter, projector *db.Projector, ) (list *db.Iterable[db.Scount], err error)
Find fetches all the scounts from colln subject to filter and projector options specified.
func (ScountCollection) FindOne ¶
func (colln ScountCollection) FindOne( ctx context.Context, id *db.ScountId, ) (s db.Scount, err error)
FindOne fetches scount from colln by id.
func (ScountCollection) Insert ¶
Insert adds one or more scounts into colln. db.ErrNoRows if empty scounts.
func (ScountCollection) UpdateOne ¶
func (colln ScountCollection) UpdateOne( ctx context.Context, id *db.ScountId, setter *db.ScountUpdater, ) error
UpdateOne modifies exactly 1 scount from `scounts` collection.
type UserCollection ¶
UserCollection provides a convenient way to interact with `users` table.
func (UserCollection) DeleteOne ¶
DeleteOne removes exactly 1 user from `users` collection based on id.
func (UserCollection) Find ¶
func (colln UserCollection) Find( ctx context.Context, filter *db.UserFilter, projector *db.Projector, ) (list *db.Iterable[db.User], err error)
Find fetches all the users from colln subject to filter and projector options specified.
func (UserCollection) FindByEmail ¶
FindByEmail fetches user from colln by email.
func (UserCollection) Insert ¶
Insert adds one or more users to colln. db.ErrNoRows if no users to insert.
func (UserCollection) UpdateOne ¶
func (colln UserCollection) UpdateOne( ctx context.Context, id *db.UserId, setter *db.UserUpdater, ) error
UpdateOne modifies exactly 1 user from `users` collection.
func (UserCollection) UpdatePassword ¶
func (colln UserCollection) UpdatePassword(ctx context.Context, updater *db.PasswordUpdater) error
UpdatePassword modifies the password of the matching user record as specified.