curd

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MySQLCount

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

MySQLCount 返回记录数

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

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

func MySQLCreate

func MySQLCreate(ctx context.Context, db qrm.DB, stmt InsertStatement) (int64, error)

MySQLCreate 创建记录

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

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

// 批量插入
table.Demo.INSERT(table.Demo.Name).
	VALUES("hello").
	VALUES("world")
// or
table.Demo.INSERT(table.Demo.Name).MODELS([]model.Demo{
	{Name: "hello"},
	{Name: "world"},
})

// 创建方法
MySQLCreate(ctx, db, stmt)

func MySQLDelete

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

MySQLDelete 删除记录

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

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

// 删除方法
MySQLDelete(ctx, db, stmt)

func MySQLFindAll

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

MySQLFindAll 查询多条记录

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

// 语句示例
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%")))

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

func MySQLFindOne

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

MySQLFindOne 查询一条记录

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

// 语句示例
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)))

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

func MySQLPaginate

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

MySQLPaginate 分页查询

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

// 查询方法
MySQLPaginate[model.Demo](ctx, 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 MySQLUpdate

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

MySQLUpdate 更新记录

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

// 语句示例
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)))

// 更新方法
MySQLUpdate(ctx, db, stmt)

func PgSQLBatchCreate

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

PgSQLBatchCreate 批量创建记录

// 导入模块
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)

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

func PgSQLCount

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

PgSQLCount 返回记录数

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

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

func PgSQLCreate

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

PgSQLCreate 创建记录

// 导入模块
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)

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

func PgSQLDelete

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

PgSQLDelete 删除记录

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

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

// 删除方法
PgSQLDelete(ctx, db, stmt)

func PgSQLFindAll

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

PgSQLFindAll 查询多条记录

// 导入模块
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%")))

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

func PgSQLFindOne

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

PgSQLFindOne 查询一条记录

// 导入模块
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)))

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

func PgSQLPaginate

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

PgSQLPaginate 分页查询

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

// 查询方法
PgSQLPaginate[model.Demo](ctx, 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 PgSQLUpdate

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

PgSQLUpdate 更新记录

// 导入模块
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)))

// 更新方法
PgSQLUpdate(ctx, db, stmt)

func SQLiteCount

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

SQLiteCount 返回记录数

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

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

func SQLiteCreate

func SQLiteCreate(ctx context.Context, db qrm.DB, stmt InsertStatement) (int64, error)

SQLiteCreate 创建记录

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

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

// 批量插入
table.Demo.INSERT(table.Demo.Name).
	VALUES("hello").
	VALUES("world")
// or
table.Demo.INSERT(table.Demo.Name).MODELS([]model.Demo{
	{Name: "hello"},
	{Name: "world"},
})

// 创建方法
SQLiteCreate(ctx, db, stmt)

func SQLiteDelete

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

SQLiteDelete 删除记录

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

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

// 删除方法
SQLiteDelete(ctx, db, stmt)

func SQLiteFindAll

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

SQLiteFindAll 查询多条记录

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

// 语句示例
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%")))

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

func SQLiteFindOne

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

SQLiteFindOne 查询一条记录

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

// 语句示例
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)))

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

func SQLitePaginate

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

SQLitePaginate 分页查询

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

// 查询方法
SQLitePaginate[model.Demo](ctx, 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 SQLiteUpdate

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

SQLiteUpdate 更新记录

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

// 语句示例
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)))

// 更新方法
SQLiteUpdate(ctx, db, stmt)

Types

type MySQLMap

type MySQLMap map[Column]any

MySQLMap 用于 MySQL 的 INSERT & UPDATE

func (MySQLMap) Split

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

type PgSQLMap

type PgSQLMap map[Column]any

PgSQLMap 用于 PostgreSQL 的 INSERT & UPDATE

func (PgSQLMap) Split

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

type SQLiteMap

type SQLiteMap map[Column]any

SQLiteMap 用于 SQLite 的 INSERT & UPDATE

func (SQLiteMap) Split

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

Jump to

Keyboard shortcuts

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