You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dingtalk/vendor/github.com/uptrace/bun
李光春 d641e26624
- update vendor
2 years ago
..
dialect - update vendor 2 years ago
driver/pgdriver - update vendor 2 years ago
extra/bunjson - update vendor 2 years ago
internal - update vendor 2 years ago
schema - update vendor 2 years ago
.gitignore - update vendor 2 years ago
.prettierrc.yml - update vendor 2 years ago
CHANGELOG.md - update vendor 2 years ago
CONTRIBUTING.md - update vendor 2 years ago
LICENSE - update vendor 2 years ago
Makefile - update vendor 2 years ago
README.md - update vendor 2 years ago
bun.go - update vendor 2 years ago
commitlint.config.js - update vendor 2 years ago
db.go - update vendor 2 years ago
hook.go - update vendor 2 years ago
model.go - update vendor 2 years ago
model_map.go - update vendor 2 years ago
model_map_slice.go - update vendor 2 years ago
model_scan.go - update vendor 2 years ago
model_slice.go - update vendor 2 years ago
model_table_has_many.go - update vendor 2 years ago
model_table_m2m.go - update vendor 2 years ago
model_table_slice.go - update vendor 2 years ago
model_table_struct.go - update vendor 2 years ago
package.json - update vendor 2 years ago
query_base.go - update vendor 2 years ago
query_column_add.go - update vendor 2 years ago
query_column_drop.go - update vendor 2 years ago
query_delete.go - update vendor 2 years ago
query_index_create.go - update vendor 2 years ago
query_index_drop.go - update vendor 2 years ago
query_insert.go - update vendor 2 years ago
query_raw.go - update vendor 2 years ago
query_select.go - update vendor 2 years ago
query_table_create.go - update vendor 2 years ago
query_table_drop.go - update vendor 2 years ago
query_table_truncate.go - update vendor 2 years ago
query_update.go - update vendor 2 years ago
query_values.go - update vendor 2 years ago
relation_join.go - update vendor 2 years ago
util.go - update vendor 2 years ago
version.go - update vendor 2 years 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 and blazingly fast distributed tracing tool powered by OpenTelemetry and ClickHouse. Give it a star as well!

Features

Resources:

Featured projects using Bun:

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

Contributors

Thanks to all the people who already contributed!