mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-04 22:20:53 +01:00
a156188b3e
* update dependencies, bump Go version to 1.19 * bump test image Go version * update golangci-lint * update gotosocial-drone-build * sign * linting, go fmt * update swagger docs * update swagger docs * whitespace * update contributing.md * fuckin whoopsie doopsie * linterino, linteroni * fix followrequest test not starting processor * fix other api/client tests not starting processor * fix remaining tests where processor not started * bump go-runners version * don't check last-webfingered-at, processor may have updated this * update swagger command * update bun to latest version * fix embed to work the same as before with new bun Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
100 lines
1.9 KiB
Go
100 lines
1.9 KiB
Go
package sqlitedialect
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/hex"
|
|
"fmt"
|
|
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/dialect"
|
|
"github.com/uptrace/bun/dialect/feature"
|
|
"github.com/uptrace/bun/dialect/sqltype"
|
|
"github.com/uptrace/bun/schema"
|
|
)
|
|
|
|
func init() {
|
|
if Version() != bun.Version() {
|
|
panic(fmt.Errorf("sqlitedialect and Bun must have the same version: v%s != v%s",
|
|
Version(), bun.Version()))
|
|
}
|
|
}
|
|
|
|
type Dialect struct {
|
|
schema.BaseDialect
|
|
|
|
tables *schema.Tables
|
|
features feature.Feature
|
|
}
|
|
|
|
func New() *Dialect {
|
|
d := new(Dialect)
|
|
d.tables = schema.NewTables(d)
|
|
d.features = feature.CTE |
|
|
feature.WithValues |
|
|
feature.Returning |
|
|
feature.InsertReturning |
|
|
feature.InsertTableAlias |
|
|
feature.UpdateTableAlias |
|
|
feature.DeleteTableAlias |
|
|
feature.InsertOnConflict |
|
|
feature.TableNotExists |
|
|
feature.SelectExists |
|
|
feature.CompositeIn
|
|
return d
|
|
}
|
|
|
|
func (d *Dialect) Init(*sql.DB) {}
|
|
|
|
func (d *Dialect) Name() dialect.Name {
|
|
return dialect.SQLite
|
|
}
|
|
|
|
func (d *Dialect) Features() feature.Feature {
|
|
return d.features
|
|
}
|
|
|
|
func (d *Dialect) Tables() *schema.Tables {
|
|
return d.tables
|
|
}
|
|
|
|
func (d *Dialect) OnTable(table *schema.Table) {
|
|
for _, field := range table.FieldMap {
|
|
d.onField(field)
|
|
}
|
|
}
|
|
|
|
func (d *Dialect) onField(field *schema.Field) {
|
|
field.DiscoveredSQLType = fieldSQLType(field)
|
|
}
|
|
|
|
func (d *Dialect) IdentQuote() byte {
|
|
return '"'
|
|
}
|
|
|
|
func (d *Dialect) AppendBytes(b []byte, bs []byte) []byte {
|
|
if bs == nil {
|
|
return dialect.AppendNull(b)
|
|
}
|
|
|
|
b = append(b, `X'`...)
|
|
|
|
s := len(b)
|
|
b = append(b, make([]byte, hex.EncodedLen(len(bs)))...)
|
|
hex.Encode(b[s:], bs)
|
|
|
|
b = append(b, '\'')
|
|
|
|
return b
|
|
}
|
|
|
|
func fieldSQLType(field *schema.Field) string {
|
|
switch field.DiscoveredSQLType {
|
|
case sqltype.SmallInt, sqltype.BigInt:
|
|
// INTEGER PRIMARY KEY is an alias for the ROWID.
|
|
// It is safe to convert all ints to INTEGER, because SQLite types don't have size.
|
|
return sqltype.Integer
|
|
default:
|
|
return field.DiscoveredSQLType
|
|
}
|
|
}
|