171 lines
4.0 KiB
Go
171 lines
4.0 KiB
Go
// Code generated by BobGen sql (devel). DO NOT EDIT.
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
|
|
|
package models
|
|
|
|
import (
|
|
"hash/maphash"
|
|
"strings"
|
|
|
|
"github.com/stephenafamo/bob"
|
|
"github.com/stephenafamo/bob/clause"
|
|
"github.com/stephenafamo/bob/dialect/sqlite"
|
|
"github.com/stephenafamo/bob/dialect/sqlite/dialect"
|
|
sqliteDriver "modernc.org/sqlite"
|
|
)
|
|
|
|
var TableNames = struct {
|
|
Files string
|
|
Items string
|
|
SchemaMigrations string
|
|
Users string
|
|
}{
|
|
Files: "file",
|
|
Items: "item",
|
|
SchemaMigrations: "schema_migrations",
|
|
Users: "user",
|
|
}
|
|
|
|
var ColumnNames = struct {
|
|
Files fileColumnNames
|
|
Items itemColumnNames
|
|
SchemaMigrations schemaMigrationColumnNames
|
|
Users userColumnNames
|
|
}{
|
|
Files: fileColumnNames{
|
|
ID: "id",
|
|
Name: "name",
|
|
Data: "data",
|
|
UserID: "user_id",
|
|
},
|
|
Items: itemColumnNames{
|
|
ID: "id",
|
|
Name: "name",
|
|
Added: "added",
|
|
Description: "description",
|
|
Price: "price",
|
|
Quantity: "quantity",
|
|
UserID: "user_id",
|
|
},
|
|
SchemaMigrations: schemaMigrationColumnNames{
|
|
Version: "version",
|
|
},
|
|
Users: userColumnNames{
|
|
ID: "id",
|
|
Username: "username",
|
|
Password: "password",
|
|
ProfilePictureID: "profile_picture_id",
|
|
},
|
|
}
|
|
|
|
var (
|
|
SelectWhere = Where[*dialect.SelectQuery]()
|
|
InsertWhere = Where[*dialect.InsertQuery]()
|
|
UpdateWhere = Where[*dialect.UpdateQuery]()
|
|
DeleteWhere = Where[*dialect.DeleteQuery]()
|
|
)
|
|
|
|
func Where[Q sqlite.Filterable]() struct {
|
|
Files fileWhere[Q]
|
|
Items itemWhere[Q]
|
|
SchemaMigrations schemaMigrationWhere[Q]
|
|
Users userWhere[Q]
|
|
} {
|
|
return struct {
|
|
Files fileWhere[Q]
|
|
Items itemWhere[Q]
|
|
SchemaMigrations schemaMigrationWhere[Q]
|
|
Users userWhere[Q]
|
|
}{
|
|
Files: buildFileWhere[Q](FileColumns),
|
|
Items: buildItemWhere[Q](ItemColumns),
|
|
SchemaMigrations: buildSchemaMigrationWhere[Q](SchemaMigrationColumns),
|
|
Users: buildUserWhere[Q](UserColumns),
|
|
}
|
|
}
|
|
|
|
var (
|
|
SelectJoins = getJoins[*dialect.SelectQuery]
|
|
UpdateJoins = getJoins[*dialect.UpdateQuery]
|
|
)
|
|
|
|
type joinSet[Q interface{ aliasedAs(string) Q }] struct {
|
|
InnerJoin Q
|
|
LeftJoin Q
|
|
RightJoin Q
|
|
}
|
|
|
|
func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] {
|
|
return joinSet[Q]{
|
|
InnerJoin: j.InnerJoin.aliasedAs(alias),
|
|
LeftJoin: j.LeftJoin.aliasedAs(alias),
|
|
RightJoin: j.RightJoin.aliasedAs(alias),
|
|
}
|
|
}
|
|
|
|
type joins[Q dialect.Joinable] struct {
|
|
Files joinSet[fileJoins[Q]]
|
|
Items joinSet[itemJoins[Q]]
|
|
Users joinSet[userJoins[Q]]
|
|
}
|
|
|
|
func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q](c C, f F) joinSet[Q] {
|
|
return joinSet[Q]{
|
|
InnerJoin: f(c, clause.InnerJoin),
|
|
LeftJoin: f(c, clause.LeftJoin),
|
|
RightJoin: f(c, clause.RightJoin),
|
|
}
|
|
}
|
|
|
|
func getJoins[Q dialect.Joinable]() joins[Q] {
|
|
return joins[Q]{
|
|
Files: buildJoinSet[fileJoins[Q]](FileColumns, buildFileJoins),
|
|
Items: buildJoinSet[itemJoins[Q]](ItemColumns, buildItemJoins),
|
|
Users: buildJoinSet[userJoins[Q]](UserColumns, buildUserJoins),
|
|
}
|
|
}
|
|
|
|
type modAs[Q any, C interface{ AliasedAs(string) C }] struct {
|
|
c C
|
|
f func(C) bob.Mod[Q]
|
|
}
|
|
|
|
func (m modAs[Q, C]) Apply(q Q) {
|
|
m.f(m.c).Apply(q)
|
|
}
|
|
|
|
func (m modAs[Q, C]) AliasedAs(alias string) bob.Mod[Q] {
|
|
m.c = m.c.AliasedAs(alias)
|
|
return m
|
|
}
|
|
|
|
func randInt() int64 {
|
|
out := int64(new(maphash.Hash).Sum64())
|
|
|
|
if out < 0 {
|
|
return -out % 10000
|
|
}
|
|
|
|
return out % 10000
|
|
}
|
|
|
|
// ErrUniqueConstraint captures all unique constraint errors by explicitly leaving `s` empty.
|
|
var ErrUniqueConstraint = &UniqueConstraintError{s: ""}
|
|
|
|
type UniqueConstraintError struct {
|
|
// s is a string uniquely identifying the constraint in the raw error message returned from the database.
|
|
s string
|
|
}
|
|
|
|
func (e *UniqueConstraintError) Error() string {
|
|
return e.s
|
|
}
|
|
|
|
func (e *UniqueConstraintError) Is(target error) bool {
|
|
err, ok := target.(*sqliteDriver.Error)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return err.Code() == 2067 && strings.Contains(err.Error(), e.s)
|
|
}
|