entx

package module
v0.0.0-...-d47c915 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSQLitePragmas = []Pragma{
	{"foreign_keys", "ON"},
	{"journal_mode", "WAL"},
	{"synchronous", "NORMAL"},
	{"busy_timeout", "30000"},
	{"temp_store", "MEMORY"},
}

DefaultSQLitePragmas are the default SQLite pragmas used when no pragmas are provided.

Functions

func Chunked

func Chunked[P PagableQuery[P, T], T any](
	ctx context.Context,
	size int,
	query PagableQuery[P, T],
) iter.Seq2[*T, error]

Chunked takes a pagable query, and yields an iterator of chunks of the results. If the size is less than 1, it will default to 250.

func ConstrainDialect

func ConstrainDialect(dsn *url.URL, dialects ...string) error

ConstrainDialect constrains the dialect of the given DSN to the given dialects, e.g. dialect.SQLite or dialect.Postgres.

func Driver

func Driver(ctx context.Context, logger *slog.Logger, dsn *url.URL) (*entsql.Driver, error)

Driver returns a new database driver for the given DSN. If logger is nil, slog.Default is used. Supports the following schemes: - sqlite3 (see DefaultSQLitePragmas for default pragmas, optimizing for single-process performance)) - sqlite (remapped to sqlite3) - file (remapped to sqlite) - memory through "sqlite::memory:", each call to MemoryDriver will create a unique in-memory database. - postgres (using pgx, with pgxpool support, see pgxpool.ParseConfig for supported pooling options).

Example:

driver, err := entx.Driver(ctx, logger, dsn)
if err != nil {
	panic(err)
}
ent.NewClient(ent.Driver(driver))

func GetMutationIDs

func GetMutationIDs(ctx context.Context, m ent.Mutation) (ids []int)

GetMutationIDs returns the entity ids addressed by the mutation, if possible. This should work for mutations that either select a single or multiple entities. If the mutation does not implement this interface, it will return nil.

func MemoryDriver

func MemoryDriver(logger *slog.Logger) *entsql.Driver

MemoryDriver returns a new SQLite driver that uses an in-memory database. This is a shortcut for Driver with the following URL: "sqlite::memory:".

func MustDriver

func MustDriver(ctx context.Context, logger *slog.Logger, dsn *url.URL) *entsql.Driver

MustDriver is a shortcut for Driver that panics if the driver creation fails.

Types

type PagableQuery

type PagableQuery[P any, T any] interface {
	Limit(int) P
	Offset(int) P
	All(context.Context) ([]*T, error)
}

PagableQuery is a query that can be paginated. All ent should implement this interface.

type Pragma

type Pragma [2]string

Pragma is a SQL pragma.

Jump to

Keyboard shortcuts

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