durcno@1.0.0-alpha.2
Minor Changes
-
6be1ac2 - Thanks to @almahdi404 !
impr(columns)!: add sqlCastScalar for prepared statement type casting
Introduces a new abstract
sqlCastScalargetter on theColumnbase class. Each column type returns either a PostgreSQL type string (e.g."uuid","boolean","jsonb") ornullwhen PostgreSQL can infer the type without an explicit cast (e.g.integer,varchar,text).A derived
sqlCastgetter onColumncomposessqlCastScalarwith array dimension suffixes automatically, matching the existingsqlTypepattern.toSQL()and the internal#toSQLArray()now accept an optional{ cast?: boolean }option. Whencast: trueis passed the generated SQL literal is suffixed with::type, ensuring cases where PostgreSQL cannot infer the type are handled correctly.Arg(used by prepared statements) now stores thesqlCastfrom the column that produced it.Query.addArg()appends::typeautomatically, and a newQuery.pushArg()helper is provided for ad-hoc use.InsertReturningQuerynow delegates toInsertQuery.toQuery()instead of duplicating the SQL-building logic, eliminating a class of divergence bugs.UpdateQuery's SET clause is simplified: both prepare and non-prepare modes now usetoSQL(..., { cast: true })inline, removing the branching that previously forced literal SQL in prepare mode.All built-in column types now implement
sqlCastScalar.Custom column authors must add
sqlCastScalarto anyColumnsubclass:get sqlCastScalar(): string | null {return "citext"; // return null if PostgreSQL can infer the type}
Patch Changes
-
3217c70 - Thanks to @almahdi404 !
fix(migration/fk): detect and generate FK reference changes
The migration generator now detects when a column's foreign key
referenceschanges between schema snapshots and emits the appropriateALTER TABLEstatements.Two new actions are added to
AlterTableBuilder:addForeignKeyanddropForeignKey. When a column gains a reference, anADD CONSTRAINT ... FOREIGN KEYstatement is emitted. When a reference is removed, the correspondingDROP CONSTRAINTstatement is emitted. If the reference target changes, a drop is followed by an add.// Generated migration when a FK is added to an existing columnalterTable("public", "posts").addForeignKey("posts_user_id_fkey", "user_id", {schema: "public",table: "users",column: "id",onDelete: "CASCADE",});// Generated migration when a FK is removed from a columnalterTable("public", "posts").dropForeignKey("posts_user_id_fkey", "user_id"); -
447fb69 - Thanks to @almahdi404 !
fix(rq): throw clear error when relation column missing .references()
When using
many,one, orfkin arelations()definition, the relation column must call.references()to declare the join target. If.references()was omitted, the relational query (db.query(...).findMany(...)) would crash with a cryptic runtime error.Now a clear
Erroris thrown with a message that identifies the offending column and tells you exactly what to fix. -
32d8cb6 - Thanks to @almahdi404 !
refac(cli): replace require with dynamic import
Replaced all synchronous
require()calls in the CLI withawait import()to use native ESM dynamic imports.getSetupinsrc/cli/helpers.tsis nowasync, and all CLI commands (down,generate,shell,squash,status) have been updated toawaitit.Migration module loading in
generateandsquashcommands was also migrated fromrequire()toawait import(). -
204fab8 - Thanks to @almahdi404 !
change(cli): remove type:module setup from init
The
initcommand no longer sets"type": "module"in theirpackage.json, and thesetTypeModule()helper has been removed entirely.This step was removed because Durcno no longer loads ESModule TypeScript files using
require(). As a result,"type": "module"is no longer a requirement imposed by Durcno, and setting it duringinitis no longer necessary.