2155 lines
52 KiB
Go
2155 lines
52 KiB
Go
// AUTOGENERATED BY gopkg.in/spacemonkeygo/dbx.v1
|
|
// DO NOT EDIT.
|
|
|
|
package dbx
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
"unicode"
|
|
|
|
"github.com/mattn/go-sqlite3"
|
|
"math/rand"
|
|
)
|
|
|
|
// Prevent conditional imports from causing build failures
|
|
var _ = strconv.Itoa
|
|
var _ = strings.LastIndex
|
|
var _ = fmt.Sprint
|
|
var _ sync.Mutex
|
|
|
|
var (
|
|
WrapErr = func(err *Error) error { return err }
|
|
Logger func(format string, args ...interface{})
|
|
|
|
errTooManyRows = errors.New("too many rows")
|
|
errUnsupportedDriver = errors.New("unsupported driver")
|
|
errEmptyUpdate = errors.New("empty update")
|
|
)
|
|
|
|
func logError(format string, args ...interface{}) {
|
|
if Logger != nil {
|
|
Logger(format, args...)
|
|
}
|
|
}
|
|
|
|
type ErrorCode int
|
|
|
|
const (
|
|
ErrorCode_Unknown ErrorCode = iota
|
|
ErrorCode_UnsupportedDriver
|
|
ErrorCode_NoRows
|
|
ErrorCode_TxDone
|
|
ErrorCode_TooManyRows
|
|
ErrorCode_ConstraintViolation
|
|
ErrorCode_EmptyUpdate
|
|
)
|
|
|
|
type Error struct {
|
|
Err error
|
|
Code ErrorCode
|
|
Driver string
|
|
Constraint string
|
|
QuerySuffix string
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
return e.Err.Error()
|
|
}
|
|
|
|
func wrapErr(e *Error) error {
|
|
if WrapErr == nil {
|
|
return e
|
|
}
|
|
return WrapErr(e)
|
|
}
|
|
|
|
func makeErr(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
e := &Error{Err: err}
|
|
switch err {
|
|
case sql.ErrNoRows:
|
|
e.Code = ErrorCode_NoRows
|
|
case sql.ErrTxDone:
|
|
e.Code = ErrorCode_TxDone
|
|
}
|
|
return wrapErr(e)
|
|
}
|
|
|
|
func unsupportedDriver(driver string) error {
|
|
return wrapErr(&Error{
|
|
Err: errUnsupportedDriver,
|
|
Code: ErrorCode_UnsupportedDriver,
|
|
Driver: driver,
|
|
})
|
|
}
|
|
|
|
func emptyUpdate() error {
|
|
return wrapErr(&Error{
|
|
Err: errEmptyUpdate,
|
|
Code: ErrorCode_EmptyUpdate,
|
|
})
|
|
}
|
|
|
|
func tooManyRows(query_suffix string) error {
|
|
return wrapErr(&Error{
|
|
Err: errTooManyRows,
|
|
Code: ErrorCode_TooManyRows,
|
|
QuerySuffix: query_suffix,
|
|
})
|
|
}
|
|
|
|
func constraintViolation(err error, constraint string) error {
|
|
return wrapErr(&Error{
|
|
Err: err,
|
|
Code: ErrorCode_ConstraintViolation,
|
|
Constraint: constraint,
|
|
})
|
|
}
|
|
|
|
type driver interface {
|
|
Exec(query string, args ...interface{}) (sql.Result, error)
|
|
Query(query string, args ...interface{}) (*sql.Rows, error)
|
|
QueryRow(query string, args ...interface{}) *sql.Row
|
|
}
|
|
|
|
var (
|
|
notAPointer = errors.New("destination not a pointer")
|
|
lossyConversion = errors.New("lossy conversion")
|
|
)
|
|
|
|
type DB struct {
|
|
*sql.DB
|
|
dbMethods
|
|
|
|
Hooks struct {
|
|
Now func() time.Time
|
|
}
|
|
}
|
|
|
|
func Open(driver, source string) (db *DB, err error) {
|
|
var sql_db *sql.DB
|
|
switch driver {
|
|
case "sqlite3":
|
|
sql_db, err = opensqlite3(source)
|
|
default:
|
|
return nil, unsupportedDriver(driver)
|
|
}
|
|
if err != nil {
|
|
return nil, makeErr(err)
|
|
}
|
|
defer func(sql_db *sql.DB) {
|
|
if err != nil {
|
|
sql_db.Close()
|
|
}
|
|
}(sql_db)
|
|
|
|
if err := sql_db.Ping(); err != nil {
|
|
return nil, makeErr(err)
|
|
}
|
|
|
|
db = &DB{
|
|
DB: sql_db,
|
|
}
|
|
db.Hooks.Now = time.Now
|
|
|
|
switch driver {
|
|
case "sqlite3":
|
|
db.dbMethods = newsqlite3(db)
|
|
default:
|
|
return nil, unsupportedDriver(driver)
|
|
}
|
|
|
|
return db, nil
|
|
}
|
|
|
|
func (obj *DB) Close() (err error) {
|
|
return obj.makeErr(obj.DB.Close())
|
|
}
|
|
|
|
func (obj *DB) Open(ctx context.Context) (*Tx, error) {
|
|
tx, err := obj.DB.Begin()
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
|
|
return &Tx{
|
|
Tx: tx,
|
|
txMethods: obj.wrapTx(tx),
|
|
}, nil
|
|
}
|
|
|
|
func (obj *DB) NewRx() *Rx {
|
|
return &Rx{db: obj}
|
|
}
|
|
|
|
func DeleteAll(ctx context.Context, db *DB) (int64, error) {
|
|
tx, err := db.Open(ctx)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer func() {
|
|
if err == nil {
|
|
err = db.makeErr(tx.Commit())
|
|
return
|
|
}
|
|
|
|
if err_rollback := tx.Rollback(); err_rollback != nil {
|
|
logError("delete-all: rollback failed: %v", db.makeErr(err_rollback))
|
|
}
|
|
}()
|
|
return tx.deleteAll(ctx)
|
|
}
|
|
|
|
type Tx struct {
|
|
Tx *sql.Tx
|
|
txMethods
|
|
}
|
|
|
|
type dialectTx struct {
|
|
tx *sql.Tx
|
|
}
|
|
|
|
func (tx *dialectTx) Commit() (err error) {
|
|
return makeErr(tx.tx.Commit())
|
|
}
|
|
|
|
func (tx *dialectTx) Rollback() (err error) {
|
|
return makeErr(tx.tx.Rollback())
|
|
}
|
|
|
|
type sqlite3Impl struct {
|
|
db *DB
|
|
dialect __sqlbundle_sqlite3
|
|
driver driver
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Rebind(s string) string {
|
|
return obj.dialect.Rebind(s)
|
|
}
|
|
|
|
func (obj *sqlite3Impl) logStmt(stmt string, args ...interface{}) {
|
|
sqlite3LogStmt(stmt, args...)
|
|
}
|
|
|
|
func (obj *sqlite3Impl) makeErr(err error) error {
|
|
constraint, ok := obj.isConstraintError(err)
|
|
if ok {
|
|
return constraintViolation(err, constraint)
|
|
}
|
|
return makeErr(err)
|
|
}
|
|
|
|
type sqlite3DB struct {
|
|
db *DB
|
|
*sqlite3Impl
|
|
}
|
|
|
|
func newsqlite3(db *DB) *sqlite3DB {
|
|
return &sqlite3DB{
|
|
db: db,
|
|
sqlite3Impl: &sqlite3Impl{
|
|
db: db,
|
|
driver: db.DB,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (obj *sqlite3DB) Schema() string {
|
|
return `CREATE TABLE projects (
|
|
id BLOB NOT NULL,
|
|
name TEXT NOT NULL,
|
|
description TEXT NOT NULL,
|
|
terms_accepted INTEGER NOT NULL,
|
|
created_at TIMESTAMP NOT NULL,
|
|
PRIMARY KEY ( id )
|
|
);
|
|
CREATE TABLE users (
|
|
id BLOB NOT NULL,
|
|
first_name TEXT NOT NULL,
|
|
last_name TEXT NOT NULL,
|
|
email TEXT NOT NULL,
|
|
password_hash BLOB NOT NULL,
|
|
created_at TIMESTAMP NOT NULL,
|
|
PRIMARY KEY ( id ),
|
|
UNIQUE ( email )
|
|
);
|
|
CREATE TABLE api_keys (
|
|
id BLOB NOT NULL,
|
|
project_id BLOB NOT NULL REFERENCES projects( id ) ON DELETE CASCADE,
|
|
key BLOB NOT NULL,
|
|
name TEXT NOT NULL,
|
|
created_at TIMESTAMP NOT NULL,
|
|
PRIMARY KEY ( id ),
|
|
UNIQUE ( key ),
|
|
UNIQUE ( name, project_id )
|
|
);
|
|
CREATE TABLE project_members (
|
|
member_id BLOB NOT NULL REFERENCES users( id ) ON DELETE CASCADE,
|
|
project_id BLOB NOT NULL REFERENCES projects( id ) ON DELETE CASCADE,
|
|
created_at TIMESTAMP NOT NULL,
|
|
PRIMARY KEY ( member_id, project_id )
|
|
);`
|
|
}
|
|
|
|
func (obj *sqlite3DB) wrapTx(tx *sql.Tx) txMethods {
|
|
return &sqlite3Tx{
|
|
dialectTx: dialectTx{tx: tx},
|
|
sqlite3Impl: &sqlite3Impl{
|
|
db: obj.db,
|
|
driver: tx,
|
|
},
|
|
}
|
|
}
|
|
|
|
type sqlite3Tx struct {
|
|
dialectTx
|
|
*sqlite3Impl
|
|
}
|
|
|
|
func sqlite3LogStmt(stmt string, args ...interface{}) {
|
|
// TODO: render placeholders
|
|
if Logger != nil {
|
|
out := fmt.Sprintf("stmt: %s\nargs: %v\n", stmt, pretty(args))
|
|
Logger(out)
|
|
}
|
|
}
|
|
|
|
type pretty []interface{}
|
|
|
|
func (p pretty) Format(f fmt.State, c rune) {
|
|
fmt.Fprint(f, "[")
|
|
nextval:
|
|
for i, val := range p {
|
|
if i > 0 {
|
|
fmt.Fprint(f, ", ")
|
|
}
|
|
rv := reflect.ValueOf(val)
|
|
if rv.Kind() == reflect.Ptr {
|
|
if rv.IsNil() {
|
|
fmt.Fprint(f, "NULL")
|
|
continue
|
|
}
|
|
val = rv.Elem().Interface()
|
|
}
|
|
switch v := val.(type) {
|
|
case string:
|
|
fmt.Fprintf(f, "%q", v)
|
|
case time.Time:
|
|
fmt.Fprintf(f, "%s", v.Format(time.RFC3339Nano))
|
|
case []byte:
|
|
for _, b := range v {
|
|
if !unicode.IsPrint(rune(b)) {
|
|
fmt.Fprintf(f, "%#x", v)
|
|
continue nextval
|
|
}
|
|
}
|
|
fmt.Fprintf(f, "%q", v)
|
|
default:
|
|
fmt.Fprintf(f, "%v", v)
|
|
}
|
|
}
|
|
fmt.Fprint(f, "]")
|
|
}
|
|
|
|
type Project struct {
|
|
Id []byte
|
|
Name string
|
|
Description string
|
|
TermsAccepted int
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (Project) _Table() string { return "projects" }
|
|
|
|
type Project_Update_Fields struct {
|
|
Description Project_Description_Field
|
|
TermsAccepted Project_TermsAccepted_Field
|
|
}
|
|
|
|
type Project_Id_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func Project_Id(v []byte) Project_Id_Field {
|
|
return Project_Id_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f Project_Id_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (Project_Id_Field) _Column() string { return "id" }
|
|
|
|
type Project_Name_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value string
|
|
}
|
|
|
|
func Project_Name(v string) Project_Name_Field {
|
|
return Project_Name_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f Project_Name_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (Project_Name_Field) _Column() string { return "name" }
|
|
|
|
type Project_Description_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value string
|
|
}
|
|
|
|
func Project_Description(v string) Project_Description_Field {
|
|
return Project_Description_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f Project_Description_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (Project_Description_Field) _Column() string { return "description" }
|
|
|
|
type Project_TermsAccepted_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value int
|
|
}
|
|
|
|
func Project_TermsAccepted(v int) Project_TermsAccepted_Field {
|
|
return Project_TermsAccepted_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f Project_TermsAccepted_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (Project_TermsAccepted_Field) _Column() string { return "terms_accepted" }
|
|
|
|
type Project_CreatedAt_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value time.Time
|
|
}
|
|
|
|
func Project_CreatedAt(v time.Time) Project_CreatedAt_Field {
|
|
return Project_CreatedAt_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f Project_CreatedAt_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (Project_CreatedAt_Field) _Column() string { return "created_at" }
|
|
|
|
type User struct {
|
|
Id []byte
|
|
FirstName string
|
|
LastName string
|
|
Email string
|
|
PasswordHash []byte
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (User) _Table() string { return "users" }
|
|
|
|
type User_Update_Fields struct {
|
|
FirstName User_FirstName_Field
|
|
LastName User_LastName_Field
|
|
Email User_Email_Field
|
|
PasswordHash User_PasswordHash_Field
|
|
}
|
|
|
|
type User_Id_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func User_Id(v []byte) User_Id_Field {
|
|
return User_Id_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f User_Id_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (User_Id_Field) _Column() string { return "id" }
|
|
|
|
type User_FirstName_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value string
|
|
}
|
|
|
|
func User_FirstName(v string) User_FirstName_Field {
|
|
return User_FirstName_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f User_FirstName_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (User_FirstName_Field) _Column() string { return "first_name" }
|
|
|
|
type User_LastName_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value string
|
|
}
|
|
|
|
func User_LastName(v string) User_LastName_Field {
|
|
return User_LastName_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f User_LastName_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (User_LastName_Field) _Column() string { return "last_name" }
|
|
|
|
type User_Email_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value string
|
|
}
|
|
|
|
func User_Email(v string) User_Email_Field {
|
|
return User_Email_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f User_Email_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (User_Email_Field) _Column() string { return "email" }
|
|
|
|
type User_PasswordHash_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func User_PasswordHash(v []byte) User_PasswordHash_Field {
|
|
return User_PasswordHash_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f User_PasswordHash_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (User_PasswordHash_Field) _Column() string { return "password_hash" }
|
|
|
|
type User_CreatedAt_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value time.Time
|
|
}
|
|
|
|
func User_CreatedAt(v time.Time) User_CreatedAt_Field {
|
|
return User_CreatedAt_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f User_CreatedAt_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (User_CreatedAt_Field) _Column() string { return "created_at" }
|
|
|
|
type ApiKey struct {
|
|
Id []byte
|
|
ProjectId []byte
|
|
Key []byte
|
|
Name string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (ApiKey) _Table() string { return "api_keys" }
|
|
|
|
type ApiKey_Update_Fields struct {
|
|
Name ApiKey_Name_Field
|
|
}
|
|
|
|
type ApiKey_Id_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func ApiKey_Id(v []byte) ApiKey_Id_Field {
|
|
return ApiKey_Id_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ApiKey_Id_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ApiKey_Id_Field) _Column() string { return "id" }
|
|
|
|
type ApiKey_ProjectId_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func ApiKey_ProjectId(v []byte) ApiKey_ProjectId_Field {
|
|
return ApiKey_ProjectId_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ApiKey_ProjectId_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ApiKey_ProjectId_Field) _Column() string { return "project_id" }
|
|
|
|
type ApiKey_Key_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func ApiKey_Key(v []byte) ApiKey_Key_Field {
|
|
return ApiKey_Key_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ApiKey_Key_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ApiKey_Key_Field) _Column() string { return "key" }
|
|
|
|
type ApiKey_Name_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value string
|
|
}
|
|
|
|
func ApiKey_Name(v string) ApiKey_Name_Field {
|
|
return ApiKey_Name_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ApiKey_Name_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ApiKey_Name_Field) _Column() string { return "name" }
|
|
|
|
type ApiKey_CreatedAt_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value time.Time
|
|
}
|
|
|
|
func ApiKey_CreatedAt(v time.Time) ApiKey_CreatedAt_Field {
|
|
return ApiKey_CreatedAt_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ApiKey_CreatedAt_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ApiKey_CreatedAt_Field) _Column() string { return "created_at" }
|
|
|
|
type ProjectMember struct {
|
|
MemberId []byte
|
|
ProjectId []byte
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (ProjectMember) _Table() string { return "project_members" }
|
|
|
|
type ProjectMember_Update_Fields struct {
|
|
}
|
|
|
|
type ProjectMember_MemberId_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func ProjectMember_MemberId(v []byte) ProjectMember_MemberId_Field {
|
|
return ProjectMember_MemberId_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ProjectMember_MemberId_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ProjectMember_MemberId_Field) _Column() string { return "member_id" }
|
|
|
|
type ProjectMember_ProjectId_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value []byte
|
|
}
|
|
|
|
func ProjectMember_ProjectId(v []byte) ProjectMember_ProjectId_Field {
|
|
return ProjectMember_ProjectId_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ProjectMember_ProjectId_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ProjectMember_ProjectId_Field) _Column() string { return "project_id" }
|
|
|
|
type ProjectMember_CreatedAt_Field struct {
|
|
_set bool
|
|
_null bool
|
|
_value time.Time
|
|
}
|
|
|
|
func ProjectMember_CreatedAt(v time.Time) ProjectMember_CreatedAt_Field {
|
|
return ProjectMember_CreatedAt_Field{_set: true, _value: v}
|
|
}
|
|
|
|
func (f ProjectMember_CreatedAt_Field) value() interface{} {
|
|
if !f._set || f._null {
|
|
return nil
|
|
}
|
|
return f._value
|
|
}
|
|
|
|
func (ProjectMember_CreatedAt_Field) _Column() string { return "created_at" }
|
|
|
|
func toUTC(t time.Time) time.Time {
|
|
return t.UTC()
|
|
}
|
|
|
|
func toDate(t time.Time) time.Time {
|
|
// keep up the minute portion so that translations between timezones will
|
|
// continue to reflect properly.
|
|
return t.Truncate(time.Minute)
|
|
}
|
|
|
|
//
|
|
// runtime support for building sql statements
|
|
//
|
|
|
|
type __sqlbundle_SQL interface {
|
|
Render() string
|
|
|
|
private()
|
|
}
|
|
|
|
type __sqlbundle_Dialect interface {
|
|
Rebind(sql string) string
|
|
}
|
|
|
|
type __sqlbundle_RenderOp int
|
|
|
|
const (
|
|
__sqlbundle_NoFlatten __sqlbundle_RenderOp = iota
|
|
__sqlbundle_NoTerminate
|
|
)
|
|
|
|
func __sqlbundle_Render(dialect __sqlbundle_Dialect, sql __sqlbundle_SQL, ops ...__sqlbundle_RenderOp) string {
|
|
out := sql.Render()
|
|
|
|
flatten := true
|
|
terminate := true
|
|
for _, op := range ops {
|
|
switch op {
|
|
case __sqlbundle_NoFlatten:
|
|
flatten = false
|
|
case __sqlbundle_NoTerminate:
|
|
terminate = false
|
|
}
|
|
}
|
|
|
|
if flatten {
|
|
out = __sqlbundle_flattenSQL(out)
|
|
}
|
|
if terminate {
|
|
out += ";"
|
|
}
|
|
|
|
return dialect.Rebind(out)
|
|
}
|
|
|
|
var __sqlbundle_reSpace = regexp.MustCompile(`\s+`)
|
|
|
|
func __sqlbundle_flattenSQL(s string) string {
|
|
return strings.TrimSpace(__sqlbundle_reSpace.ReplaceAllString(s, " "))
|
|
}
|
|
|
|
// this type is specially named to match up with the name returned by the
|
|
// dialect impl in the sql package.
|
|
type __sqlbundle_postgres struct{}
|
|
|
|
func (p __sqlbundle_postgres) Rebind(sql string) string {
|
|
out := make([]byte, 0, len(sql)+10)
|
|
|
|
j := 1
|
|
for i := 0; i < len(sql); i++ {
|
|
ch := sql[i]
|
|
if ch != '?' {
|
|
out = append(out, ch)
|
|
continue
|
|
}
|
|
|
|
out = append(out, '$')
|
|
out = append(out, strconv.Itoa(j)...)
|
|
j++
|
|
}
|
|
|
|
return string(out)
|
|
}
|
|
|
|
// this type is specially named to match up with the name returned by the
|
|
// dialect impl in the sql package.
|
|
type __sqlbundle_sqlite3 struct{}
|
|
|
|
func (s __sqlbundle_sqlite3) Rebind(sql string) string {
|
|
return sql
|
|
}
|
|
|
|
type __sqlbundle_Literal string
|
|
|
|
func (__sqlbundle_Literal) private() {}
|
|
|
|
func (l __sqlbundle_Literal) Render() string { return string(l) }
|
|
|
|
type __sqlbundle_Literals struct {
|
|
Join string
|
|
SQLs []__sqlbundle_SQL
|
|
}
|
|
|
|
func (__sqlbundle_Literals) private() {}
|
|
|
|
func (l __sqlbundle_Literals) Render() string {
|
|
var out bytes.Buffer
|
|
|
|
first := true
|
|
for _, sql := range l.SQLs {
|
|
if sql == nil {
|
|
continue
|
|
}
|
|
if !first {
|
|
out.WriteString(l.Join)
|
|
}
|
|
first = false
|
|
out.WriteString(sql.Render())
|
|
}
|
|
|
|
return out.String()
|
|
}
|
|
|
|
type __sqlbundle_Condition struct {
|
|
// set at compile/embed time
|
|
Name string
|
|
Left string
|
|
Equal bool
|
|
Right string
|
|
|
|
// set at runtime
|
|
Null bool
|
|
}
|
|
|
|
func (*__sqlbundle_Condition) private() {}
|
|
|
|
func (c *__sqlbundle_Condition) Render() string {
|
|
|
|
switch {
|
|
case c.Equal && c.Null:
|
|
return c.Left + " is null"
|
|
case c.Equal && !c.Null:
|
|
return c.Left + " = " + c.Right
|
|
case !c.Equal && c.Null:
|
|
return c.Left + " is not null"
|
|
case !c.Equal && !c.Null:
|
|
return c.Left + " != " + c.Right
|
|
default:
|
|
panic("unhandled case")
|
|
}
|
|
}
|
|
|
|
type __sqlbundle_Hole struct {
|
|
// set at compiile/embed time
|
|
Name string
|
|
|
|
// set at runtime
|
|
SQL __sqlbundle_SQL
|
|
}
|
|
|
|
func (*__sqlbundle_Hole) private() {}
|
|
|
|
func (h *__sqlbundle_Hole) Render() string { return h.SQL.Render() }
|
|
|
|
//
|
|
// end runtime support for building sql statements
|
|
//
|
|
|
|
func (obj *sqlite3Impl) Create_User(ctx context.Context,
|
|
user_id User_Id_Field,
|
|
user_first_name User_FirstName_Field,
|
|
user_last_name User_LastName_Field,
|
|
user_email User_Email_Field,
|
|
user_password_hash User_PasswordHash_Field) (
|
|
user *User, err error) {
|
|
|
|
__now := obj.db.Hooks.Now().UTC()
|
|
__id_val := user_id.value()
|
|
__first_name_val := user_first_name.value()
|
|
__last_name_val := user_last_name.value()
|
|
__email_val := user_email.value()
|
|
__password_hash_val := user_password_hash.value()
|
|
__created_at_val := __now
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("INSERT INTO users ( id, first_name, last_name, email, password_hash, created_at ) VALUES ( ?, ?, ?, ?, ?, ? )")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __id_val, __first_name_val, __last_name_val, __email_val, __password_hash_val, __created_at_val)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __id_val, __first_name_val, __last_name_val, __email_val, __password_hash_val, __created_at_val)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
__pk, err := __res.LastInsertId()
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return obj.getLastUser(ctx, __pk)
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Create_Project(ctx context.Context,
|
|
project_id Project_Id_Field,
|
|
project_name Project_Name_Field,
|
|
project_description Project_Description_Field,
|
|
project_terms_accepted Project_TermsAccepted_Field) (
|
|
project *Project, err error) {
|
|
|
|
__now := obj.db.Hooks.Now().UTC()
|
|
__id_val := project_id.value()
|
|
__name_val := project_name.value()
|
|
__description_val := project_description.value()
|
|
__terms_accepted_val := project_terms_accepted.value()
|
|
__created_at_val := __now
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("INSERT INTO projects ( id, name, description, terms_accepted, created_at ) VALUES ( ?, ?, ?, ?, ? )")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __id_val, __name_val, __description_val, __terms_accepted_val, __created_at_val)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __id_val, __name_val, __description_val, __terms_accepted_val, __created_at_val)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
__pk, err := __res.LastInsertId()
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return obj.getLastProject(ctx, __pk)
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Create_ProjectMember(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field,
|
|
project_member_project_id ProjectMember_ProjectId_Field) (
|
|
project_member *ProjectMember, err error) {
|
|
|
|
__now := obj.db.Hooks.Now().UTC()
|
|
__member_id_val := project_member_member_id.value()
|
|
__project_id_val := project_member_project_id.value()
|
|
__created_at_val := __now
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("INSERT INTO project_members ( member_id, project_id, created_at ) VALUES ( ?, ?, ? )")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __member_id_val, __project_id_val, __created_at_val)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __member_id_val, __project_id_val, __created_at_val)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
__pk, err := __res.LastInsertId()
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return obj.getLastProjectMember(ctx, __pk)
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Create_ApiKey(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field,
|
|
api_key_project_id ApiKey_ProjectId_Field,
|
|
api_key_key ApiKey_Key_Field,
|
|
api_key_name ApiKey_Name_Field) (
|
|
api_key *ApiKey, err error) {
|
|
|
|
__now := obj.db.Hooks.Now().UTC()
|
|
__id_val := api_key_id.value()
|
|
__project_id_val := api_key_project_id.value()
|
|
__key_val := api_key_key.value()
|
|
__name_val := api_key_name.value()
|
|
__created_at_val := __now
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("INSERT INTO api_keys ( id, project_id, key, name, created_at ) VALUES ( ?, ?, ?, ?, ? )")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __id_val, __project_id_val, __key_val, __name_val, __created_at_val)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __id_val, __project_id_val, __key_val, __name_val, __created_at_val)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
__pk, err := __res.LastInsertId()
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return obj.getLastApiKey(ctx, __pk)
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Get_User_By_Email(ctx context.Context,
|
|
user_email User_Email_Field) (
|
|
user *User, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at FROM users WHERE users.email = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, user_email.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
user = &User{}
|
|
err = obj.driver.QueryRow(__stmt, __values...).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return user, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Get_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field) (
|
|
user *User, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at FROM users WHERE users.id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, user_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
user = &User{}
|
|
err = obj.driver.QueryRow(__stmt, __values...).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return user, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) All_Project(ctx context.Context) (
|
|
rows []*Project, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values)
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__rows, err := obj.driver.Query(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
defer __rows.Close()
|
|
|
|
for __rows.Next() {
|
|
project := &Project{}
|
|
err = __rows.Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
rows = append(rows, project)
|
|
}
|
|
if err := __rows.Err(); err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return rows, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Get_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field) (
|
|
project *Project, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, project_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
project = &Project{}
|
|
err = obj.driver.QueryRow(__stmt, __values...).Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return project, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) All_Project_By_ProjectMember_MemberId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field) (
|
|
rows []*Project, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects JOIN project_members ON projects.id = project_members.project_id WHERE project_members.member_id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, project_member_member_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__rows, err := obj.driver.Query(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
defer __rows.Close()
|
|
|
|
for __rows.Next() {
|
|
project := &Project{}
|
|
err = __rows.Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
rows = append(rows, project)
|
|
}
|
|
if err := __rows.Err(); err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return rows, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) All_ProjectMember_By_MemberId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field) (
|
|
rows []*ProjectMember, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT project_members.member_id, project_members.project_id, project_members.created_at FROM project_members WHERE project_members.member_id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, project_member_member_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__rows, err := obj.driver.Query(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
defer __rows.Close()
|
|
|
|
for __rows.Next() {
|
|
project_member := &ProjectMember{}
|
|
err = __rows.Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
rows = append(rows, project_member)
|
|
}
|
|
if err := __rows.Err(); err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return rows, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
|
project_member_project_id ProjectMember_ProjectId_Field,
|
|
limit int, offset int64) (
|
|
rows []*ProjectMember, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT project_members.member_id, project_members.project_id, project_members.created_at FROM project_members WHERE project_members.project_id = ? LIMIT ? OFFSET ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, project_member_project_id.value())
|
|
|
|
__values = append(__values, limit, offset)
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__rows, err := obj.driver.Query(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
defer __rows.Close()
|
|
|
|
for __rows.Next() {
|
|
project_member := &ProjectMember{}
|
|
err = __rows.Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
rows = append(rows, project_member)
|
|
}
|
|
if err := __rows.Err(); err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return rows, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Get_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field) (
|
|
api_key *ApiKey, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at FROM api_keys WHERE api_keys.id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, api_key_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
api_key = &ApiKey{}
|
|
err = obj.driver.QueryRow(__stmt, __values...).Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return api_key, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) All_ApiKey_By_ProjectId_OrderBy_Asc_Name(ctx context.Context,
|
|
api_key_project_id ApiKey_ProjectId_Field) (
|
|
rows []*ApiKey, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at FROM api_keys WHERE api_keys.project_id = ? ORDER BY api_keys.name")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, api_key_project_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__rows, err := obj.driver.Query(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
defer __rows.Close()
|
|
|
|
for __rows.Next() {
|
|
api_key := &ApiKey{}
|
|
err = __rows.Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
rows = append(rows, api_key)
|
|
}
|
|
if err := __rows.Err(); err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return rows, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Update_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field,
|
|
update User_Update_Fields) (
|
|
user *User, err error) {
|
|
var __sets = &__sqlbundle_Hole{}
|
|
|
|
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE users SET "), __sets, __sqlbundle_Literal(" WHERE users.id = ?")}}
|
|
|
|
__sets_sql := __sqlbundle_Literals{Join: ", "}
|
|
var __values []interface{}
|
|
var __args []interface{}
|
|
|
|
if update.FirstName._set {
|
|
__values = append(__values, update.FirstName.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("first_name = ?"))
|
|
}
|
|
|
|
if update.LastName._set {
|
|
__values = append(__values, update.LastName.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("last_name = ?"))
|
|
}
|
|
|
|
if update.Email._set {
|
|
__values = append(__values, update.Email.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("email = ?"))
|
|
}
|
|
|
|
if update.PasswordHash._set {
|
|
__values = append(__values, update.PasswordHash.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("password_hash = ?"))
|
|
}
|
|
|
|
if len(__sets_sql.SQLs) == 0 {
|
|
return nil, emptyUpdate()
|
|
}
|
|
|
|
__args = append(__args, user_id.value())
|
|
|
|
__values = append(__values, __args...)
|
|
__sets.SQL = __sets_sql
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
user = &User{}
|
|
_, err = obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
|
|
var __embed_stmt_get = __sqlbundle_Literal("SELECT users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at FROM users WHERE users.id = ?")
|
|
|
|
var __stmt_get = __sqlbundle_Render(obj.dialect, __embed_stmt_get)
|
|
obj.logStmt("(IMPLIED) "+__stmt_get, __args...)
|
|
|
|
err = obj.driver.QueryRow(__stmt_get, __args...).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return user, nil
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Update_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field,
|
|
update Project_Update_Fields) (
|
|
project *Project, err error) {
|
|
var __sets = &__sqlbundle_Hole{}
|
|
|
|
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE projects SET "), __sets, __sqlbundle_Literal(" WHERE projects.id = ?")}}
|
|
|
|
__sets_sql := __sqlbundle_Literals{Join: ", "}
|
|
var __values []interface{}
|
|
var __args []interface{}
|
|
|
|
if update.Description._set {
|
|
__values = append(__values, update.Description.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("description = ?"))
|
|
}
|
|
|
|
if update.TermsAccepted._set {
|
|
__values = append(__values, update.TermsAccepted.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("terms_accepted = ?"))
|
|
}
|
|
|
|
if len(__sets_sql.SQLs) == 0 {
|
|
return nil, emptyUpdate()
|
|
}
|
|
|
|
__args = append(__args, project_id.value())
|
|
|
|
__values = append(__values, __args...)
|
|
__sets.SQL = __sets_sql
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
project = &Project{}
|
|
_, err = obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
|
|
var __embed_stmt_get = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
|
|
|
|
var __stmt_get = __sqlbundle_Render(obj.dialect, __embed_stmt_get)
|
|
obj.logStmt("(IMPLIED) "+__stmt_get, __args...)
|
|
|
|
err = obj.driver.QueryRow(__stmt_get, __args...).Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return project, nil
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Update_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field,
|
|
update ApiKey_Update_Fields) (
|
|
api_key *ApiKey, err error) {
|
|
var __sets = &__sqlbundle_Hole{}
|
|
|
|
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE api_keys SET "), __sets, __sqlbundle_Literal(" WHERE api_keys.id = ?")}}
|
|
|
|
__sets_sql := __sqlbundle_Literals{Join: ", "}
|
|
var __values []interface{}
|
|
var __args []interface{}
|
|
|
|
if update.Name._set {
|
|
__values = append(__values, update.Name.value())
|
|
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("name = ?"))
|
|
}
|
|
|
|
if len(__sets_sql.SQLs) == 0 {
|
|
return nil, emptyUpdate()
|
|
}
|
|
|
|
__args = append(__args, api_key_id.value())
|
|
|
|
__values = append(__values, __args...)
|
|
__sets.SQL = __sets_sql
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
api_key = &ApiKey{}
|
|
_, err = obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
|
|
var __embed_stmt_get = __sqlbundle_Literal("SELECT api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at FROM api_keys WHERE api_keys.id = ?")
|
|
|
|
var __stmt_get = __sqlbundle_Render(obj.dialect, __embed_stmt_get)
|
|
obj.logStmt("(IMPLIED) "+__stmt_get, __args...)
|
|
|
|
err = obj.driver.QueryRow(__stmt_get, __args...).Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return api_key, nil
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Delete_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field) (
|
|
deleted bool, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("DELETE FROM users WHERE users.id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, user_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err := __res.RowsAffected()
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
return __count > 0, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Delete_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field) (
|
|
deleted bool, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("DELETE FROM projects WHERE projects.id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, project_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err := __res.RowsAffected()
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
return __count > 0, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Delete_ProjectMember_By_MemberId_And_ProjectId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field,
|
|
project_member_project_id ProjectMember_ProjectId_Field) (
|
|
deleted bool, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("DELETE FROM project_members WHERE project_members.member_id = ? AND project_members.project_id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, project_member_member_id.value(), project_member_project_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err := __res.RowsAffected()
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
return __count > 0, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) Delete_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field) (
|
|
deleted bool, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("DELETE FROM api_keys WHERE api_keys.id = ?")
|
|
|
|
var __values []interface{}
|
|
__values = append(__values, api_key_id.value())
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, __values...)
|
|
|
|
__res, err := obj.driver.Exec(__stmt, __values...)
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err := __res.RowsAffected()
|
|
if err != nil {
|
|
return false, obj.makeErr(err)
|
|
}
|
|
|
|
return __count > 0, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) getLastUser(ctx context.Context,
|
|
pk int64) (
|
|
user *User, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at FROM users WHERE _rowid_ = ?")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, pk)
|
|
|
|
user = &User{}
|
|
err = obj.driver.QueryRow(__stmt, pk).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return user, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) getLastProject(ctx context.Context,
|
|
pk int64) (
|
|
project *Project, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE _rowid_ = ?")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, pk)
|
|
|
|
project = &Project{}
|
|
err = obj.driver.QueryRow(__stmt, pk).Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return project, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) getLastProjectMember(ctx context.Context,
|
|
pk int64) (
|
|
project_member *ProjectMember, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT project_members.member_id, project_members.project_id, project_members.created_at FROM project_members WHERE _rowid_ = ?")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, pk)
|
|
|
|
project_member = &ProjectMember{}
|
|
err = obj.driver.QueryRow(__stmt, pk).Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return project_member, nil
|
|
|
|
}
|
|
|
|
func (obj *sqlite3Impl) getLastApiKey(ctx context.Context,
|
|
pk int64) (
|
|
api_key *ApiKey, err error) {
|
|
|
|
var __embed_stmt = __sqlbundle_Literal("SELECT api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at FROM api_keys WHERE _rowid_ = ?")
|
|
|
|
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
|
obj.logStmt(__stmt, pk)
|
|
|
|
api_key = &ApiKey{}
|
|
err = obj.driver.QueryRow(__stmt, pk).Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
|
if err != nil {
|
|
return nil, obj.makeErr(err)
|
|
}
|
|
return api_key, nil
|
|
|
|
}
|
|
|
|
func (impl sqlite3Impl) isConstraintError(err error) (
|
|
constraint string, ok bool) {
|
|
if e, ok := err.(sqlite3.Error); ok {
|
|
if e.Code == sqlite3.ErrConstraint {
|
|
msg := err.Error()
|
|
colon := strings.LastIndex(msg, ":")
|
|
if colon != -1 {
|
|
return strings.TrimSpace(msg[colon:]), true
|
|
}
|
|
return "", true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
func (obj *sqlite3Impl) deleteAll(ctx context.Context) (count int64, err error) {
|
|
var __res sql.Result
|
|
var __count int64
|
|
__res, err = obj.driver.Exec("DELETE FROM project_members;")
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err = __res.RowsAffected()
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
count += __count
|
|
__res, err = obj.driver.Exec("DELETE FROM api_keys;")
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err = __res.RowsAffected()
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
count += __count
|
|
__res, err = obj.driver.Exec("DELETE FROM users;")
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err = __res.RowsAffected()
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
count += __count
|
|
__res, err = obj.driver.Exec("DELETE FROM projects;")
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
|
|
__count, err = __res.RowsAffected()
|
|
if err != nil {
|
|
return 0, obj.makeErr(err)
|
|
}
|
|
count += __count
|
|
|
|
return count, nil
|
|
|
|
}
|
|
|
|
type Rx struct {
|
|
db *DB
|
|
tx *Tx
|
|
}
|
|
|
|
func (rx *Rx) UnsafeTx(ctx context.Context) (unsafe_tx *sql.Tx, err error) {
|
|
tx, err := rx.getTx(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return tx.Tx, nil
|
|
}
|
|
|
|
func (rx *Rx) getTx(ctx context.Context) (tx *Tx, err error) {
|
|
if rx.tx == nil {
|
|
if rx.tx, err = rx.db.Open(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return rx.tx, nil
|
|
}
|
|
|
|
func (rx *Rx) Rebind(s string) string {
|
|
return rx.db.Rebind(s)
|
|
}
|
|
|
|
func (rx *Rx) Commit() (err error) {
|
|
if rx.tx != nil {
|
|
err = rx.tx.Commit()
|
|
rx.tx = nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (rx *Rx) Rollback() (err error) {
|
|
if rx.tx != nil {
|
|
err = rx.tx.Rollback()
|
|
rx.tx = nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (rx *Rx) All_ApiKey_By_ProjectId_OrderBy_Asc_Name(ctx context.Context,
|
|
api_key_project_id ApiKey_ProjectId_Field) (
|
|
rows []*ApiKey, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.All_ApiKey_By_ProjectId_OrderBy_Asc_Name(ctx, api_key_project_id)
|
|
}
|
|
|
|
func (rx *Rx) All_Project(ctx context.Context) (
|
|
rows []*Project, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.All_Project(ctx)
|
|
}
|
|
|
|
func (rx *Rx) All_ProjectMember_By_MemberId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field) (
|
|
rows []*ProjectMember, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.All_ProjectMember_By_MemberId(ctx, project_member_member_id)
|
|
}
|
|
|
|
func (rx *Rx) All_Project_By_ProjectMember_MemberId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field) (
|
|
rows []*Project, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.All_Project_By_ProjectMember_MemberId(ctx, project_member_member_id)
|
|
}
|
|
|
|
func (rx *Rx) Create_ApiKey(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field,
|
|
api_key_project_id ApiKey_ProjectId_Field,
|
|
api_key_key ApiKey_Key_Field,
|
|
api_key_name ApiKey_Name_Field) (
|
|
api_key *ApiKey, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Create_ApiKey(ctx, api_key_id, api_key_project_id, api_key_key, api_key_name)
|
|
|
|
}
|
|
|
|
func (rx *Rx) Create_Project(ctx context.Context,
|
|
project_id Project_Id_Field,
|
|
project_name Project_Name_Field,
|
|
project_description Project_Description_Field,
|
|
project_terms_accepted Project_TermsAccepted_Field) (
|
|
project *Project, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Create_Project(ctx, project_id, project_name, project_description, project_terms_accepted)
|
|
|
|
}
|
|
|
|
func (rx *Rx) Create_ProjectMember(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field,
|
|
project_member_project_id ProjectMember_ProjectId_Field) (
|
|
project_member *ProjectMember, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Create_ProjectMember(ctx, project_member_member_id, project_member_project_id)
|
|
|
|
}
|
|
|
|
func (rx *Rx) Create_User(ctx context.Context,
|
|
user_id User_Id_Field,
|
|
user_first_name User_FirstName_Field,
|
|
user_last_name User_LastName_Field,
|
|
user_email User_Email_Field,
|
|
user_password_hash User_PasswordHash_Field) (
|
|
user *User, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Create_User(ctx, user_id, user_first_name, user_last_name, user_email, user_password_hash)
|
|
|
|
}
|
|
|
|
func (rx *Rx) Delete_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field) (
|
|
deleted bool, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Delete_ApiKey_By_Id(ctx, api_key_id)
|
|
}
|
|
|
|
func (rx *Rx) Delete_ProjectMember_By_MemberId_And_ProjectId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field,
|
|
project_member_project_id ProjectMember_ProjectId_Field) (
|
|
deleted bool, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Delete_ProjectMember_By_MemberId_And_ProjectId(ctx, project_member_member_id, project_member_project_id)
|
|
}
|
|
|
|
func (rx *Rx) Delete_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field) (
|
|
deleted bool, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Delete_Project_By_Id(ctx, project_id)
|
|
}
|
|
|
|
func (rx *Rx) Delete_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field) (
|
|
deleted bool, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Delete_User_By_Id(ctx, user_id)
|
|
}
|
|
|
|
func (rx *Rx) Get_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field) (
|
|
api_key *ApiKey, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Get_ApiKey_By_Id(ctx, api_key_id)
|
|
}
|
|
|
|
func (rx *Rx) Get_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field) (
|
|
project *Project, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Get_Project_By_Id(ctx, project_id)
|
|
}
|
|
|
|
func (rx *Rx) Get_User_By_Email(ctx context.Context,
|
|
user_email User_Email_Field) (
|
|
user *User, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Get_User_By_Email(ctx, user_email)
|
|
}
|
|
|
|
func (rx *Rx) Get_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field) (
|
|
user *User, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Get_User_By_Id(ctx, user_id)
|
|
}
|
|
|
|
func (rx *Rx) Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
|
project_member_project_id ProjectMember_ProjectId_Field,
|
|
limit int, offset int64) (
|
|
rows []*ProjectMember, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Limited_ProjectMember_By_ProjectId(ctx, project_member_project_id, limit, offset)
|
|
}
|
|
|
|
func (rx *Rx) Update_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field,
|
|
update ApiKey_Update_Fields) (
|
|
api_key *ApiKey, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Update_ApiKey_By_Id(ctx, api_key_id, update)
|
|
}
|
|
|
|
func (rx *Rx) Update_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field,
|
|
update Project_Update_Fields) (
|
|
project *Project, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Update_Project_By_Id(ctx, project_id, update)
|
|
}
|
|
|
|
func (rx *Rx) Update_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field,
|
|
update User_Update_Fields) (
|
|
user *User, err error) {
|
|
var tx *Tx
|
|
if tx, err = rx.getTx(ctx); err != nil {
|
|
return
|
|
}
|
|
return tx.Update_User_By_Id(ctx, user_id, update)
|
|
}
|
|
|
|
type Methods interface {
|
|
All_ApiKey_By_ProjectId_OrderBy_Asc_Name(ctx context.Context,
|
|
api_key_project_id ApiKey_ProjectId_Field) (
|
|
rows []*ApiKey, err error)
|
|
|
|
All_Project(ctx context.Context) (
|
|
rows []*Project, err error)
|
|
|
|
All_ProjectMember_By_MemberId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field) (
|
|
rows []*ProjectMember, err error)
|
|
|
|
All_Project_By_ProjectMember_MemberId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field) (
|
|
rows []*Project, err error)
|
|
|
|
Create_ApiKey(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field,
|
|
api_key_project_id ApiKey_ProjectId_Field,
|
|
api_key_key ApiKey_Key_Field,
|
|
api_key_name ApiKey_Name_Field) (
|
|
api_key *ApiKey, err error)
|
|
|
|
Create_Project(ctx context.Context,
|
|
project_id Project_Id_Field,
|
|
project_name Project_Name_Field,
|
|
project_description Project_Description_Field,
|
|
project_terms_accepted Project_TermsAccepted_Field) (
|
|
project *Project, err error)
|
|
|
|
Create_ProjectMember(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field,
|
|
project_member_project_id ProjectMember_ProjectId_Field) (
|
|
project_member *ProjectMember, err error)
|
|
|
|
Create_User(ctx context.Context,
|
|
user_id User_Id_Field,
|
|
user_first_name User_FirstName_Field,
|
|
user_last_name User_LastName_Field,
|
|
user_email User_Email_Field,
|
|
user_password_hash User_PasswordHash_Field) (
|
|
user *User, err error)
|
|
|
|
Delete_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field) (
|
|
deleted bool, err error)
|
|
|
|
Delete_ProjectMember_By_MemberId_And_ProjectId(ctx context.Context,
|
|
project_member_member_id ProjectMember_MemberId_Field,
|
|
project_member_project_id ProjectMember_ProjectId_Field) (
|
|
deleted bool, err error)
|
|
|
|
Delete_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field) (
|
|
deleted bool, err error)
|
|
|
|
Delete_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field) (
|
|
deleted bool, err error)
|
|
|
|
Get_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field) (
|
|
api_key *ApiKey, err error)
|
|
|
|
Get_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field) (
|
|
project *Project, err error)
|
|
|
|
Get_User_By_Email(ctx context.Context,
|
|
user_email User_Email_Field) (
|
|
user *User, err error)
|
|
|
|
Get_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field) (
|
|
user *User, err error)
|
|
|
|
Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
|
project_member_project_id ProjectMember_ProjectId_Field,
|
|
limit int, offset int64) (
|
|
rows []*ProjectMember, err error)
|
|
|
|
Update_ApiKey_By_Id(ctx context.Context,
|
|
api_key_id ApiKey_Id_Field,
|
|
update ApiKey_Update_Fields) (
|
|
api_key *ApiKey, err error)
|
|
|
|
Update_Project_By_Id(ctx context.Context,
|
|
project_id Project_Id_Field,
|
|
update Project_Update_Fields) (
|
|
project *Project, err error)
|
|
|
|
Update_User_By_Id(ctx context.Context,
|
|
user_id User_Id_Field,
|
|
update User_Update_Fields) (
|
|
user *User, err error)
|
|
}
|
|
|
|
type TxMethods interface {
|
|
Methods
|
|
|
|
Rebind(s string) string
|
|
Commit() error
|
|
Rollback() error
|
|
}
|
|
|
|
type txMethods interface {
|
|
TxMethods
|
|
|
|
deleteAll(ctx context.Context) (int64, error)
|
|
makeErr(err error) error
|
|
}
|
|
|
|
type DBMethods interface {
|
|
Methods
|
|
|
|
Schema() string
|
|
Rebind(sql string) string
|
|
}
|
|
|
|
type dbMethods interface {
|
|
DBMethods
|
|
|
|
wrapTx(tx *sql.Tx) txMethods
|
|
makeErr(err error) error
|
|
}
|
|
|
|
var sqlite3DriverName = func() string {
|
|
var id [16]byte
|
|
rand.Read(id[:])
|
|
return fmt.Sprintf("sqlite3_%x", string(id[:]))
|
|
}()
|
|
|
|
func init() {
|
|
sql.Register(sqlite3DriverName, &sqlite3.SQLiteDriver{
|
|
ConnectHook: sqlite3SetupConn,
|
|
})
|
|
}
|
|
|
|
// SQLite3JournalMode controls the journal_mode pragma for all new connections.
|
|
// Since it is read without a mutex, it must be changed to the value you want
|
|
// before any Open calls.
|
|
var SQLite3JournalMode = "WAL"
|
|
|
|
func sqlite3SetupConn(conn *sqlite3.SQLiteConn) (err error) {
|
|
_, err = conn.Exec("PRAGMA foreign_keys = ON", nil)
|
|
if err != nil {
|
|
return makeErr(err)
|
|
}
|
|
_, err = conn.Exec("PRAGMA journal_mode = "+SQLite3JournalMode, nil)
|
|
if err != nil {
|
|
return makeErr(err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func opensqlite3(source string) (*sql.DB, error) {
|
|
return sql.Open(sqlite3DriverName, source)
|
|
}
|