From 67ac8db190eb82a7758746fb021fa3014f4241b7 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sun, 12 Dec 2021 15:47:51 +0100 Subject: Upstep Go dependencies (#340) * Upstep Go dependencies * tiny linter fix * Tidy --- vendor/github.com/uptrace/bun/README.md | 149 ++------------------------------ 1 file changed, 5 insertions(+), 144 deletions(-) (limited to 'vendor/github.com/uptrace/bun/README.md') diff --git a/vendor/github.com/uptrace/bun/README.md b/vendor/github.com/uptrace/bun/README.md index 0c27b9a37..2eeff3bc1 100644 --- a/vendor/github.com/uptrace/bun/README.md +++ b/vendor/github.com/uptrace/bun/README.md @@ -29,10 +29,10 @@ Main features are: Resources: -- [Discussions](https://github.com/uptrace/bun/discussions). -- [Newsletter](https://blog.uptrace.dev/pages/newsletter.html) to get latest updates. +- [**Get started**](https://bun.uptrace.dev/guide/getting-started.html) - [Examples](https://github.com/uptrace/bun/tree/master/example) -- [Documentation](https://bun.uptrace.dev/) +- [Discussions](https://github.com/uptrace/bun/discussions) +- [Newsletter](https://blog.uptrace.dev/pages/newsletter.html) to get latest updates. - [Reference](https://pkg.go.dev/github.com/uptrace/bun) - [Starter kit](https://github.com/go-bun/bun-starter-kit) @@ -156,147 +156,8 @@ go get github.com/uptrace/bun You also need to install a database/sql driver and the corresponding Bun [dialect](https://bun.uptrace.dev/guide/drivers.html). -## Quickstart - -First you need to create a `sql.DB`. Here we are using the -[sqliteshim](https://pkg.go.dev/github.com/uptrace/bun/driver/sqliteshim) driver which chooses -between [modernc.org/sqlite](https://modernc.org/sqlite/) and -[mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) depending on your platform. - -```go -import "github.com/uptrace/bun/driver/sqliteshim" - -sqldb, err := sql.Open(sqliteshim.ShimName, "file::memory:?cache=shared") -if err != nil { - panic(err) -} -``` - -And then create a `bun.DB` on top of it using the corresponding SQLite -[dialect](https://bun.uptrace.dev/guide/drivers.html) that comes with Bun: - -```go -import ( - "github.com/uptrace/bun" - "github.com/uptrace/bun/dialect/sqlitedialect" -) - -db := bun.NewDB(sqldb, sqlitedialect.New()) -``` - -Now you are ready to issue some queries: - -```go -type User struct { - ID int64 - Name string -} - -user := new(User) -err := db.NewSelect(). - Model(user). - Where("name != ?", ""). - OrderExpr("id ASC"). - Limit(1). - Scan(ctx) -``` - -## Basic example - -To provide initial data for our [example](/example/basic/), we will use Bun -[fixtures](https://bun.uptrace.dev/guide/fixtures.html): - -```go -import "github.com/uptrace/bun/dbfixture" - -// Register models for the fixture. -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.yml which contains data for User and Story models. -if err := fixture.Load(ctx, os.DirFS("."), "fixture.yml"); err != nil { - panic(err) -} -``` - -The `fixture.yml` looks like this: - -```yaml -- model: User - rows: - - _id: admin - name: admin - emails: ['admin1@admin', 'admin2@admin'] - - _id: root - name: root - emails: ['root1@root', 'root2@root'] - -- model: Story - rows: - - title: Cool story - author_id: '{{ $.User.admin.ID }}' -``` - -To select all users: - -```go -users := make([]User, 0) -if err := db.NewSelect().Model(&users).OrderExpr("id ASC").Scan(ctx); err != nil { - panic(err) -} -``` - -To select a single user by id: - -```go -user1 := new(User) -if err := db.NewSelect().Model(user1).Where("id = ?", 1).Scan(ctx); err != nil { - panic(err) -} -``` - -To select a story and the associated author in a single query: - -```go -story := new(Story) -if err := db.NewSelect(). - Model(story). - Relation("Author"). - Limit(1). - Scan(ctx); err != nil { - panic(err) -} -``` - -To select a user into a map: - -```go -m := make(map[string]interface{}) -if err := db.NewSelect(). - Model((*User)(nil)). - Limit(1). - Scan(ctx, &m); err != nil { - panic(err) -} -``` - -To select all users scanning each column into a separate slice: - -```go -var ids []int64 -var names []string -if err := db.NewSelect(). - ColumnExpr("id, name"). - Model((*User)(nil)). - OrderExpr("id ASC"). - Scan(ctx, &ids, &names); err != nil { - panic(err) -} -``` - -For more details, please consult [docs](https://bun.uptrace.dev/) and check [examples](example). +See [**Getting started**](https://bun.uptrace.dev/guide/getting-started.html) guide and check +[examples](example). ## Contributors -- cgit v1.3