Help us shape the future of Go! Take the 2026 Go Developer Survey

pgsql

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchCreate

func BatchCreate[T any](ctx context.Context, db qrm.DB, stmt InsertStatement) ([]T, error)

BatchCreate 批量创建记录

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 语句示例
table.Demo.INSERT(table.Demo.Name).
	VALUES("hello").
	VALUES("world").
	RETURNING(table.Demo.AllColumns)
// or
table.Demo.INSERT(table.Demo.Name).MODELS([]model.Demo{
	{Name: "hello"},
	{Name: "world"},
}).RETURNING(table.Demo.AllColumns)

// 创建方法
pgsql.BatchCreate[model.Demo](ctx, db.DB(), stmt)

func Count

func Count(ctx context.Context, db qrm.DB, fn func(count SelectStatement) SelectStatement) (int64, error)

Count 返回记录数

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 查询方法
pgsql.Count(ctx, db.DB(), func(count SelectStatement) SelectStatement {
	return count.FROM(table.Demo.Table).WHERE(table.Demo.Name.LIKE(String("%hello%")))
})

func Create

func Create[T any](ctx context.Context, db qrm.DB, stmt InsertStatement) (T, error)

Create 创建记录

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 语句示例
table.Demo.INSERT(table.Demo.Name).VALUES("hello").RETURNING(table.Demo.AllColumns)
// or
table.Demo.INSERT(table.Demo.Name).MODEL(model.Demo{Name: "hello"}).RETURNING(table.Demo.AllColumns)

// 创建方法
pgsql.Create[model.Demo](ctx, db.DB(), stmt)

func Delete

func Delete(ctx context.Context, db qrm.DB, stmt DeleteStatement) (int64, error)

Delete 删除记录

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 语句示例
table.Demo.DELETE().WHERE(table.Demo.ID.EQ(Int64(1)))

// 删除方法
pgsql.Delete(ctx, db.DB(), stmt)

func FindAll

func FindAll[T any](ctx context.Context, db qrm.DB, stmt SelectStatement) ([]T, error)

FindAll 查询多条记录

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 语句示例
table.Demo.SELECT(table.Demo.AllColumns).WHERE(table.Demo.Name.LIKE(String("%hello%")))
// or
SELECT(table.Demo.AllColumns).FROM(table.Demo).WHERE(table.Demo.Name.LIKE(String("%hello%")))

// 查询方法
pgsql.FindAll[model.Demo](ctx, db.DB(), stmt)

func FindOne

func FindOne[T any](ctx context.Context, db qrm.DB, stmt SelectStatement) (*T, error)

FindOne 查询一条记录

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 语句示例
table.Demo.SELECT(table.Demo.AllColumns).WHERE(table.Demo.ID.EQ(Int64(1)))
// or
SELECT(table.Demo.AllColumns).FROM(table.Demo).WHERE(table.Demo.ID.EQ(Int64(1)))

// 查询方法
pgsql.FindOne[model.Demo](ctx, db.DB(), stmt)

func Paginate

func Paginate[T any](ctx context.Context, db qrm.DB, fn func(query SelectStatement) SelectStatement, page, size int, cols ColumnList, orderBy ...OrderByClause) ([]T, int64, error)

Paginate 分页查询

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 查询方法
pgsql.Paginate[model.Demo](ctx, db.DB(), func(query SelectStatement) SelectStatement {
	return query.FROM(table.Demo.Table).WHERE(table.Demo.Name.LIKE(String("%hello%")))
}, page, size, table.Demo.AllColumns, table.Demo.ID.DESC())

func Update

func Update(ctx context.Context, db qrm.DB, stmt UpdateStatement) (int64, error)

Update 更新记录

// 导入模块
import . "github.com/go-jet/jet/v2/postgres"

// 语句示例
table.Demo.UPDATE(table.Demo.Name).SET("hello").WHERE(table.Demo.ID.EQ(Int64(1)))
// or
table.Demo.UPDATE(table.Demo.Name).MODEL(model.Demo{Name: "hello"}).WHERE(table.Demo.ID.EQ(Int64(1)))

// 更新方法
pgsql.Update(ctx, db.DB(), stmt)

Types

type M

type M map[Column]any

M 用于 INSERT & UPDATE

func (M) Split

func (m M) Split() (cols ColumnList, vals []any)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL