You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gotosocial/vendor/github.com/uptrace/bun
kim 1018cde107
[chore] bump bun library versions (#2837)
7 months ago
..
dialect [chore] bump bun library versions (#2837) 7 months ago
extra [chore] bump bun v1.1.14 -> v1.1.15 (#2195) 1 year ago
internal [chore] bump bun library versions (#2837) 7 months ago
migrate [chore] bump bun library versions (#2837) 7 months ago
schema [chore] bump bun library versions (#2837) 7 months ago
.gitignore [chore] update bun + extras v1.1.16 -> v1.1.17 (#2534) 10 months ago
.prettierrc.yml upstep bun to v1.0.14 (#291) 3 years ago
CHANGELOG.md [chore] bump bun library versions (#2837) 7 months ago
CONTRIBUTING.md [chore] Update bun and sqlite dependencies (#478) 3 years ago
LICENSE Pg to bun (#148) 3 years ago
Makefile [chore] bump bun library versions (#2837) 7 months ago
README.md [chore] bump db dependencies (#1366) 2 years ago
bun.go [chore] bump bun library versions (#2837) 7 months ago
commitlint.config.js update bun library to latest commit (#206) 3 years ago
db.go [chore] bump db dependencies (#1366) 2 years ago
hook.go [chore] bump db dependencies (#1366) 2 years ago
model.go [chore] Update a bunch of database dependencies (#1772) 2 years ago
model_map.go upstep bun to v1.0.14 (#291) 3 years ago
model_map_slice.go upstep bun to v1.0.14 (#291) 3 years ago
model_scan.go upstep bun to v1.0.14 (#291) 3 years ago
model_slice.go upstep bun to v1.0.9 (#252) 3 years ago
model_table_has_many.go [chore] bump bun library versions (#2837) 7 months ago
model_table_m2m.go upstep bun to v1.0.9 (#252) 3 years ago
model_table_slice.go [chore] Update uptrace/bun and modernc/sqlite dependencies (#1598) 2 years ago
model_table_struct.go [chore] bump bun library versions (#2837) 7 months ago
package.json [chore] bump bun library versions (#2837) 7 months ago
query_base.go [chore] bump bun library versions (#2837) 7 months ago
query_column_add.go [chore] bump db dependencies (#1366) 2 years ago
query_column_drop.go [chore] bump db dependencies (#1366) 2 years ago
query_delete.go [chore] bump db dependencies (#1366) 2 years ago
query_index_create.go [chore] bump db dependencies (#1366) 2 years ago
query_index_drop.go [chore] bump db dependencies (#1366) 2 years ago
query_insert.go [chore] update bun + extras v1.1.16 -> v1.1.17 (#2534) 10 months ago
query_merge.go [chore] update bun + extras v1.1.16 -> v1.1.17 (#2534) 10 months ago
query_raw.go [chore] Update a bunch of database dependencies (#1772) 2 years ago
query_select.go [chore] bump bun v1.1.14 -> v1.1.15 (#2195) 1 year ago
query_table_create.go [chore] update bun + extras v1.1.16 -> v1.1.17 (#2534) 10 months ago
query_table_drop.go [chore] bump db dependencies (#1366) 2 years ago
query_table_truncate.go [chore] bump db dependencies (#1366) 2 years ago
query_update.go [chore] update bun + extras v1.1.16 -> v1.1.17 (#2534) 10 months ago
query_values.go [chore] bump db dependencies (#1366) 2 years ago
relation_join.go [chore] bump bun library versions (#2837) 7 months ago
util.go [chore] bump db dependencies (#1366) 2 years ago
version.go [chore] bump bun library versions (#2837) 7 months ago

README.md

SQL-first Golang ORM for PostgreSQL, MySQL, MSSQL, and SQLite

build workflow PkgGoDev Documentation Chat

Bun is brought to you by uptrace/uptrace. Uptrace is an open-source APM tool that supports distributed tracing, metrics, and logs. You can use it to monitor applications and set up automatic alerts to receive notifications via email, Slack, Telegram, and others.

See OpenTelemetry example which demonstrates how you can use Uptrace to monitor Bun.

Features

Resources

Tutorials

Wrote a tutorial for Bun? Create a PR to add here and on Bun site.

Why another database client?

So you can elegantly write complex queries:

regionalSales := db.NewSelect().
	ColumnExpr("region").
	ColumnExpr("SUM(amount) AS total_sales").
	TableExpr("orders").
	GroupExpr("region")

topRegions := db.NewSelect().
	ColumnExpr("region").
	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).
	ColumnExpr("region").
	ColumnExpr("product").
	ColumnExpr("SUM(quantity) AS product_units").
	ColumnExpr("SUM(amount) AS product_sales").
	TableExpr("orders").
	Where("region IN (SELECT region FROM top_regions)").
	GroupExpr("region").
	GroupExpr("product").
	Scan(ctx, &items)
WITH regional_sales AS (
    SELECT region, SUM(amount) AS total_sales
    FROM orders
    GROUP BY region
), top_regions AS (
    SELECT region
    FROM regional_sales
    WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
)
SELECT region,
       product,
       SUM(quantity) AS product_units,
       SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product

And scan results into scalars, structs, maps, slices of structs/maps/scalars:

users := make([]User, 0)
if err := db.NewSelect().Model(&users).OrderExpr("id ASC").Scan(ctx); err != nil {
	panic(err)
}

user1 := new(User)
if err := db.NewSelect().Model(user1).Where("id = ?", 1).Scan(ctx); err != nil {
	panic(err)
}

See Getting started guide and check examples.

See also

Contributing

See CONTRIBUTING.md for some hints.

And thanks to all the people who already contributed!