durcno@1.0.0-alpha.13
Major Changes
-
e09cdfe - Thanks to @almahdi404 !
change(migration/ddl)!: remove deprecated enum DDL helpers
Removed the deprecated enum-specific DDL helpers that were superseded by the generic type API in v1.0.0-alpha.4.
Removed from
ddl:ddl.createEnum()→ useddl.createType(schema, name, { asEnum: [...] })insteadddl.alterEnumAddValue()→ useddl.alterType(schema, name).addValue(...)insteadddl.dropEnum()→ useddl.dropType(schema, name)instead
Removed classes (were re-exported from
durcno/migration):CreateEnumStatementAlterEnumAddValueStatementDropEnumStatement
Removed from
DDLStatementType:"createEnum","alterEnum","dropEnum". -
093303c - Thanks to @almahdi404 !
change!(insert): replace $insertReturning with returning("*")
The
db.$insertReturning()shortcut has been removed. Use.insert().values(...).returning("*")instead to insert a row and get back all columns including auto-generated values.returning("*")is a new overload onInsertQuerythat emitsRETURNING *and returns a fully-typed array of the inserted rows. It works for both single-row and multi-row inserts.// Before (removed)const user = await db.$insertReturning(Users, {username: "john",type: "user",});// Afterconst [user] = await db.insert(Users).values({ username: "john", type: "user" }).returning("*");console.log(user.id); // auto-generated IDconsole.log(user.createdAt); // auto-generated timestamp
Minor Changes
-
afa2485 - Thanks to @almahdi404 !
feat(query-builder): support bigint and Arg for limit/offset
limitandoffsetin bothdb.fromanddb.querynow acceptbigintin addition tonumber.For prepared queries,
limitandoffsetcan be parameterized using the newArg.number()andArg.bigint()static factory methods onArg. This enables paginated prepared statements where the page size and offset vary at runtime.const paginatedUsers = prequery({ lim: Arg.number(), off: Arg.number() },(args) =>db.prepare().from(Users).select().limit(args.lim).offset(args.off),);const page1 = await paginatedUsers.run(db, { lim: 10, off: 0 });const page2 = await paginatedUsers.run(db, { lim: 10, off: 10 });offsetis also now supported inside nestedmanyrelation options inRelationQueryBuilder, matching the existingwhere,orderBy, andlimitsupport. -
49cf1ae - Thanks to @almahdi404 !
feat(constraints): add column-level check constraints
Adds support for defining CHECK constraints directly on column definitions using the new
.check()method. This allows for more intuitive constraint definitions at the column level.Key Changes
- Column.check(): New method to attach a CHECK constraint function to a column that receives the column and returns a filter or SQL expression
- Type System Updates: Updated filter functions (
arrayContains,arrayHas, etc.) and constraint types to accept both table columns and individual columns via the newAnyColumntype - CheckExpression Enhancement: The
CheckExpressiontype now supports bothTableAnyColumnandAnyColumnfor greater flexibility
Example
export const Projects = table("public", "projects", {name: varchar({ length: 255 }).check((c) => gte(length(c), 5)),budget: integer().check((c) => gte(c, 1)),});This provides a cleaner, more declarative way to define column constraints compared to table-level constraint definitions.