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

pgsql

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchInsert added in v0.10.4

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

BatchInsert 批量插入记录

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

// 语句示例
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.BatchInsert[model.Demo](ctx, db, stmt)

func Bools added in v0.10.4

func Bools(values []bool) []Expression

func Count

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

Count 返回记录数

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

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

func Decimals added in v0.10.4

func Decimals(values []string) []Expression

func Delete

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

Delete 删除记录

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

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

// 执行方法
pgsql.Delete(ctx, db, stmt)

func Exprs added in v0.10.4

func Exprs[T any](values []T, fn func(T) Expression) []Expression

Exprs 将一组值转换为 Expression 列表,常用于 IN 查询

func FindAll

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

FindAll 查询多条记录

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

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

// 执行方法
pgsql.FindAll[*model.Demo](ctx, db, stmt)

func FindOne

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

FindOne 查询一条记录

注意:参数 T 必须为非指针类型

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

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

// 执行方法
pgsql.FindOne[model.Demo](ctx, db, stmt)

func Floats added in v0.10.4

func Floats(values []float64) []Expression

func Insert added in v0.10.4

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

Insert 插入记录

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

// 语句示例
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.Insert[model.Demo](ctx, db, stmt)

func Int8s added in v0.10.4

func Int8s(values []int8) []Expression

func Int16s added in v0.10.4

func Int16s(values []int16) []Expression

func Int32s added in v0.10.4

func Int32s(values []int32) []Expression

func Int64s added in v0.10.4

func Int64s(values []int64) []Expression

func Ints added in v0.10.4

func Ints(values []int) []Expression

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 (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

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

func Strings added in v0.10.4

func Strings(values []string) []Expression

func Uint8s added in v0.10.4

func Uint8s(values []uint8) []Expression

func Uint16s added in v0.10.4

func Uint16s(values []uint16) []Expression

func Uint32s added in v0.10.4

func Uint32s(values []uint32) []Expression

func Uint64s added in v0.10.4

func Uint64s(values []uint64) []Expression

func Uints added in v0.10.4

func Uints(values []uint) []Expression

func Update

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

Update 更新记录

// 导入模块
import (
	jet "github.com/go-jet/jet/v2/postgres"
	"github.com/noble-gase/ne/sqlkit/pgsql"
)

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

// 执行方法
pgsql.Update(ctx, db, stmt)

Types

type M

type M map[Column]any

M 用于 PostgreSQL 的 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