Documentation
¶
Index ¶
- Variables
- func Chunked[P PagableQuery[P, T], T any](ctx context.Context, size int, query PagableQuery[P, T]) iter.Seq2[*T, error]
- func ConstrainDialect(dsn *url.URL, dialects ...string) error
- func Driver(ctx context.Context, logger *slog.Logger, dsn *url.URL) (*entsql.Driver, error)
- func GetMutationIDs(ctx context.Context, m ent.Mutation) (ids []int)
- func MemoryDriver(logger *slog.Logger) *entsql.Driver
- func MustDriver(ctx context.Context, logger *slog.Logger, dsn *url.URL) *entsql.Driver
- type PagableQuery
- type Pragma
Constants ¶
This section is empty.
Variables ¶
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 ¶
ConstrainDialect constrains the dialect of the given DSN to the given dialects, e.g. dialect.SQLite or dialect.Postgres.
func Driver ¶
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 ¶
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 ¶
MemoryDriver returns a new SQLite driver that uses an in-memory database. This is a shortcut for Driver with the following URL: "sqlite::memory:".