Update dependencies (#333)

This commit is contained in:
tobi 2021-11-27 15:26:58 +01:00 committed by GitHub
commit 182b4eea73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
848 changed files with 377869 additions and 107280 deletions

View file

@ -1,3 +1,20 @@
## [1.0.18](https://github.com/uptrace/bun/compare/v1.0.17...v1.0.18) (2021-11-24)
### Bug Fixes
* use correct operation for UpdateQuery ([687a004](https://github.com/uptrace/bun/commit/687a004ef7ec6fe1ef06c394965dd2c2d822fc82))
### Features
* add pgdriver.Notify ([7ee443d](https://github.com/uptrace/bun/commit/7ee443d1b869d8ddc4746850f7425d0a9ccd012b))
* CreateTableQuery.PartitionBy and CreateTableQuery.TableSpace ([cd3ab4d](https://github.com/uptrace/bun/commit/cd3ab4d8f3682f5a30b87c2ebc2d7e551d739078))
* **pgdriver:** add CopyFrom and CopyTo ([0b97703](https://github.com/uptrace/bun/commit/0b977030b5c05f509e11d13550b5f99dfd62358d))
* support InsertQuery.Ignore on PostgreSQL ([1aa9d14](https://github.com/uptrace/bun/commit/1aa9d149da8e46e63ff79192e394fde4d18d9b60))
## [1.0.17](https://github.com/uptrace/bun/compare/v1.0.16...v1.0.17) (2021-11-11)

View file

@ -9,7 +9,6 @@
[![build workflow](https://github.com/uptrace/bun/actions/workflows/build.yml/badge.svg)](https://github.com/uptrace/bun/actions)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/uptrace/bun)](https://pkg.go.dev/github.com/uptrace/bun)
[![Documentation](https://img.shields.io/badge/bun-documentation-informational)](https://bun.uptrace.dev/)
[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)
**Status**: API freeze (stable release). Note that all sub-packages (mainly extra/\* packages) are
not part of the API freeze and are developed independently. You can think of them as of 3rd party
@ -20,10 +19,10 @@ Main features are:
- Works with [PostgreSQL](https://bun.uptrace.dev/guide/drivers.html#postgresql),
[MySQL](https://bun.uptrace.dev/guide/drivers.html#mysql) (including MariaDB),
[SQLite](https://bun.uptrace.dev/guide/drivers.html#sqlite).
- [Selecting](/example/basic/) into a map, struct, slice of maps/structs/vars.
- [Bulk inserts](https://bun.uptrace.dev/guide/queries.html#insert).
- [Bulk updates](https://bun.uptrace.dev/guide/queries.html#update) using common table expressions.
- [Bulk deletes](https://bun.uptrace.dev/guide/queries.html#delete).
- [Selecting](/example/basic/) into scalars, structs, maps, slices of maps/structs/scalars.
- [Bulk inserts](https://bun.uptrace.dev/guide/query-insert.html).
- [Bulk updates](https://bun.uptrace.dev/guide/query-update.html) using common table expressions.
- [Bulk deletes](https://bun.uptrace.dev/guide/query-delete.html).
- [Fixtures](https://bun.uptrace.dev/guide/fixtures.html).
- [Migrations](https://bun.uptrace.dev/guide/migrations.html).
- [Soft deletes](https://bun.uptrace.dev/guide/soft-deletes.html).
@ -40,7 +39,8 @@ Resources:
Projects using Bun:
- [gotosocial](https://github.com/superseriousbusiness/gotosocial) - Golang fediverse server.
- [input-output-hk/cicero](https://github.com/input-output-hk/cicero)
- [qvalet](https://github.com/cmaster11/qvalet) listens for HTTP requests and executes commands on
demand.
- [RealWorld app](https://github.com/go-bun/bun-realworld-app)
<details>
@ -111,6 +111,7 @@ topRegions := db.NewSelect().
TableExpr("regional_sales").
Where("total_sales > (SELECT SUM(total_sales) / 10 FROM regional_sales)")
var items map[string]interface{}
err := db.NewSelect().
With("regional_sales", regionalSales).
With("top_regions", topRegions).
@ -122,7 +123,7 @@ err := db.NewSelect().
Where("region IN (SELECT region FROM top_regions)").
GroupExpr("region").
GroupExpr("product").
Scan(ctx)
Scan(ctx, &items)
```
```sql
@ -144,6 +145,8 @@ WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product
```
And scan results into scalars, structs, maps, slices of structs/maps/scalars.
## Installation
```go
@ -212,13 +215,13 @@ db.RegisterModel((*User)(nil), (*Story)(nil))
// WithRecreateTables tells Bun to drop existing tables and create new ones.
fixture := dbfixture.New(db, dbfixture.WithRecreateTables())
// Load fixture.yaml which contains data for User and Story models.
if err := fixture.Load(ctx, os.DirFS("."), "fixture.yaml"); err != nil {
// Load fixture.yml which contains data for User and Story models.
if err := fixture.Load(ctx, os.DirFS("."), "fixture.yml"); err != nil {
panic(err)
}
```
The `fixture.yaml` looks like this:
The `fixture.yml` looks like this:
```yaml
- model: User

View file

@ -178,6 +178,8 @@ func (db *DB) Table(typ reflect.Type) *schema.Table {
return db.dialect.Tables().Get(typ)
}
// RegisterModel registers models by name so they can be referenced in table relations
// and fixtures.
func (db *DB) RegisterModel(models ...interface{}) {
db.dialect.Tables().Register(models...)
}
@ -201,6 +203,11 @@ func (db *DB) Formatter() schema.Formatter {
return db.fmter
}
// HasFeature uses feature package to report whether the underlying DBMS supports this feature.
func (db *DB) HasFeature(feat feature.Feature) bool {
return db.fmter.HasFeature(feat)
}
//------------------------------------------------------------------------------
func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error) {

View file

@ -17,5 +17,7 @@ const (
TableCascade
TableIdentity
TableTruncate
OnDuplicateKey
InsertOnConflict // INSERT ... ON CONFLICT
InsertOnDuplicateKey // INSERT ... ON DUPLICATE KEY
InsertIgnore // INSERT IGNORE ...
)

View file

@ -31,7 +31,8 @@ func New() *Dialect {
feature.DeleteTableAlias |
feature.TableCascade |
feature.TableIdentity |
feature.TableTruncate
feature.TableTruncate |
feature.InsertOnConflict
return d
}

View file

@ -23,7 +23,8 @@ func New() *Dialect {
d.features = feature.CTE |
feature.Returning |
feature.InsertTableAlias |
feature.DeleteTableAlias
feature.DeleteTableAlias |
feature.InsertOnConflict
return d
}

View file

@ -1,6 +1,6 @@
{
"name": "bun",
"version": "1.0.17",
"version": "1.0.18",
"main": "index.js",
"repository": "git@github.com:uptrace/bun.git",
"author": "Vladimir Mihailenco <vladimir.webdev@gmail.com>",

View file

@ -133,9 +133,16 @@ func (q *InsertQuery) hasReturning() bool {
//------------------------------------------------------------------------------
// Ignore generates an `INSERT IGNORE INTO` query (MySQL).
// Ignore generates different queries depending on the DBMS:
// - On MySQL, it generates `INSERT IGNORE INTO`.
// - On PostgreSQL, it generates `ON CONFLICT DO NOTHING`.
func (q *InsertQuery) Ignore() *InsertQuery {
q.ignore = true
if q.db.fmter.HasFeature(feature.InsertOnConflict) {
return q.On("CONFLICT DO NOTHING")
}
if q.db.fmter.HasFeature(feature.InsertIgnore) {
q.ignore = true
}
return q
}
@ -421,7 +428,7 @@ func (q *InsertQuery) appendOn(fmter schema.Formatter, b []byte) (_ []byte, err
}
if len(q.set) > 0 {
if fmter.HasFeature(feature.OnDuplicateKey) {
if fmter.HasFeature(feature.InsertOnDuplicateKey) {
b = append(b, ' ')
} else {
b = append(b, " SET "...)

View file

@ -90,6 +90,18 @@ func (q *CreateTableQuery) ForeignKey(query string, args ...interface{}) *Create
return q
}
func (q *CreateTableQuery) PartitionBy(query string, args ...interface{}) *CreateTableQuery {
q.partitionBy = schema.SafeQuery(query, args)
return q
}
func (q *CreateTableQuery) TableSpace(tablespace string) *CreateTableQuery {
q.tablespace = schema.UnsafeIdent(tablespace)
return q
}
//------------------------------------------------------------------------------
func (q *CreateTableQuery) Operation() string {
return "CREATE TABLE"
}

View file

@ -166,7 +166,7 @@ func (q *UpdateQuery) hasReturning() bool {
//------------------------------------------------------------------------------
func (q *UpdateQuery) Operation() string {
return "SELECT"
return "UPDATE"
}
func (q *UpdateQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error) {

View file

@ -2,5 +2,5 @@ package bun
// Version is the current release version.
func Version() string {
return "1.0.17"
return "1.0.18"
}