summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/uptrace')
-rw-r--r--vendor/github.com/uptrace/bun/dialect/sqlitedialect/LICENSE24
-rw-r--r--vendor/github.com/uptrace/bun/dialect/sqlitedialect/dialect.go94
-rw-r--r--vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.mod7
-rw-r--r--vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.sum22
-rw-r--r--vendor/github.com/uptrace/bun/dialect/sqlitedialect/scan.go28
5 files changed, 175 insertions, 0 deletions
diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/LICENSE b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/LICENSE
new file mode 100644
index 000000000..7ec81810c
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2021 Vladimir Mihailenco. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/dialect.go b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/dialect.go
new file mode 100644
index 000000000..33d25f2d1
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/dialect.go
@@ -0,0 +1,94 @@
+package sqlitedialect
+
+import (
+ "database/sql"
+ "reflect"
+ "sync"
+
+ "github.com/uptrace/bun/dialect"
+ "github.com/uptrace/bun/dialect/feature"
+ "github.com/uptrace/bun/dialect/sqltype"
+ "github.com/uptrace/bun/schema"
+)
+
+type Dialect struct {
+ tables *schema.Tables
+ features feature.Feature
+
+ appenderMap sync.Map
+ scannerMap sync.Map
+}
+
+func New() *Dialect {
+ d := new(Dialect)
+ d.tables = schema.NewTables(d)
+ d.features = feature.Returning | feature.InsertTableAlias | feature.DeleteTableAlias
+ 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) {
+ // 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.
+ switch field.DiscoveredSQLType {
+ case sqltype.SmallInt, sqltype.BigInt:
+ field.DiscoveredSQLType = sqltype.Integer
+ }
+}
+
+func (d *Dialect) IdentQuote() byte {
+ return '"'
+}
+
+func (d *Dialect) Append(fmter schema.Formatter, b []byte, v interface{}) []byte {
+ return schema.Append(fmter, b, v, nil)
+}
+
+func (d *Dialect) Appender(typ reflect.Type) schema.AppenderFunc {
+ if v, ok := d.appenderMap.Load(typ); ok {
+ return v.(schema.AppenderFunc)
+ }
+
+ fn := schema.Appender(typ, nil)
+
+ if v, ok := d.appenderMap.LoadOrStore(typ, fn); ok {
+ return v.(schema.AppenderFunc)
+ }
+ return fn
+}
+
+func (d *Dialect) FieldAppender(field *schema.Field) schema.AppenderFunc {
+ return schema.FieldAppender(d, field)
+}
+
+func (d *Dialect) Scanner(typ reflect.Type) schema.ScannerFunc {
+ if v, ok := d.scannerMap.Load(typ); ok {
+ return v.(schema.ScannerFunc)
+ }
+
+ fn := scanner(typ)
+
+ if v, ok := d.scannerMap.LoadOrStore(typ, fn); ok {
+ return v.(schema.ScannerFunc)
+ }
+ return fn
+}
diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.mod b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.mod
new file mode 100644
index 000000000..1fb9b7ab1
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.mod
@@ -0,0 +1,7 @@
+module github.com/uptrace/bun/dialect/sqlitedialect
+
+go 1.16
+
+replace github.com/uptrace/bun => ../..
+
+require github.com/uptrace/bun v0.4.3
diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.sum b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.sum
new file mode 100644
index 000000000..4d0f1c1bb
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.sum
@@ -0,0 +1,22 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
+github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
+github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
+github.com/vmihailenco/msgpack/v5 v5.3.4 h1:qMKAwOV+meBw2Y8k9cVwAy7qErtYCwBzZ2ellBfvnqc=
+github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
+github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
+github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
+golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
+golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/scan.go b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/scan.go
new file mode 100644
index 000000000..44c50c2e9
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/scan.go
@@ -0,0 +1,28 @@
+package sqlitedialect
+
+import (
+ "fmt"
+ "reflect"
+
+ "github.com/uptrace/bun/schema"
+)
+
+func scanner(typ reflect.Type) schema.ScannerFunc {
+ if typ.Kind() == reflect.Interface {
+ return scanInterface
+ }
+ return schema.Scanner(typ)
+}
+
+func scanInterface(dest reflect.Value, src interface{}) error {
+ if dest.IsNil() {
+ dest.Set(reflect.ValueOf(src))
+ return nil
+ }
+
+ dest = dest.Elem()
+ if fn := scanner(dest.Type()); fn != nil {
+ return fn(dest, src)
+ }
+ return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type())
+}