Documentation
¶
Index ¶
- func BatchCreate[T any](ctx context.Context, db qrm.DB, stmt InsertStatement) ([]T, error)
- func Count(ctx context.Context, db qrm.DB, fn func(count SelectStatement) SelectStatement) (int64, error)
- func Create[T any](ctx context.Context, db qrm.DB, stmt InsertStatement) (T, error)
- func Delete(ctx context.Context, db qrm.DB, stmt DeleteStatement) (int64, error)
- func FindAll[T any](ctx context.Context, db qrm.DB, stmt SelectStatement) ([]T, error)
- func FindOne[T any](ctx context.Context, db qrm.DB, stmt SelectStatement) (*T, error)
- func Paginate[T any](ctx context.Context, db qrm.DB, fn func(query SelectStatement) SelectStatement, ...) ([]T, int64, error)
- func Update(ctx context.Context, db qrm.DB, stmt UpdateStatement) (int64, error)
- type M
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchCreate ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.