@coffre/db 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dialect.d.ts +6 -0
- package/dist/dialect.js +12 -1
- package/package.json +2 -2
- package/src/dialect.ts +14 -0
package/dist/dialect.d.ts
CHANGED
|
@@ -74,6 +74,12 @@ export declare function clock(db: Queryable): SQL<string>;
|
|
|
74
74
|
* before one written while it waited. Read it in a statement after the lock.
|
|
75
75
|
*/
|
|
76
76
|
export declare function clockMillis(db: Queryable): SQL<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Whether a timestamp column is still ahead of the database clock as the
|
|
79
|
+
* statement runs: a condition, for a write that must not land once the
|
|
80
|
+
* time it names has passed.
|
|
81
|
+
*/
|
|
82
|
+
export declare function ahead(db: Queryable, column: SQLWrapper): SQL;
|
|
77
83
|
/**
|
|
78
84
|
* The migrator's own ledger, read by readiness to tell a database that is
|
|
79
85
|
* up but not yet migrated from one that is ready. Drizzle keeps it in a
|
package/dist/dialect.js
CHANGED
|
@@ -124,6 +124,17 @@ function clockMillis(db) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
|
+
* Whether a timestamp column is still ahead of the database clock as the
|
|
128
|
+
* statement runs: a condition, for a write that must not land once the
|
|
129
|
+
* time it names has passed.
|
|
130
|
+
*/
|
|
131
|
+
function ahead(db, column) {
|
|
132
|
+
switch (engineOf(db)) {
|
|
133
|
+
case "postgres": return sql`${column} > clock_timestamp()`;
|
|
134
|
+
case "sqlite": return sql`${column} > CAST(unixepoch('subsec') * 1000 AS INTEGER)`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
127
138
|
* The migrator's own ledger, read by readiness to tell a database that is
|
|
128
139
|
* up but not yet migrated from one that is ready. Drizzle keeps it in a
|
|
129
140
|
* `drizzle` schema on Postgres, and in a plain table elsewhere.
|
|
@@ -158,4 +169,4 @@ function canonicalTimestamp(raw) {
|
|
|
158
169
|
return `${(/* @__PURE__ */ new Date(Date.UTC(+year, +month - 1, +day, +hour, +minute, +second) - offsetMinutes * 6e4)).toISOString().slice(0, 19)}.${fraction.padEnd(6, "0")}Z`;
|
|
159
170
|
}
|
|
160
171
|
//#endregion
|
|
161
|
-
export { SNAPSHOT, canonicalTimestamp, changedRows, clock, clockMillis, engineOf, forUpdate, insertIfAbsent, isUniqueViolation, isUnreachable, migrationLedger, tombstone, truth, upsert };
|
|
172
|
+
export { SNAPSHOT, ahead, canonicalTimestamp, changedRows, clock, clockMillis, engineOf, forUpdate, insertIfAbsent, isUniqueViolation, isUnreachable, migrationLedger, tombstone, truth, upsert };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffre/db",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "coffre's database: the schema, its migrations and the connections, on Postgres or SQLite.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"drizzle-orm": "0.45.2",
|
|
80
80
|
"pg": "8.16.3",
|
|
81
81
|
"pg-connection-string": "2.14.0",
|
|
82
|
-
"@coffre/core": "0.4.
|
|
82
|
+
"@coffre/core": "0.4.6"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@types/node": "26.1.1",
|
package/src/dialect.ts
CHANGED
|
@@ -156,6 +156,20 @@ export function clockMillis(db: Queryable): SQL<number> {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Whether a timestamp column is still ahead of the database clock as the
|
|
161
|
+
* statement runs: a condition, for a write that must not land once the
|
|
162
|
+
* time it names has passed.
|
|
163
|
+
*/
|
|
164
|
+
export function ahead(db: Queryable, column: SQLWrapper): SQL {
|
|
165
|
+
switch (engineOf(db)) {
|
|
166
|
+
case 'postgres':
|
|
167
|
+
return sql`${column} > clock_timestamp()`;
|
|
168
|
+
case 'sqlite':
|
|
169
|
+
return sql`${column} > CAST(unixepoch('subsec') * 1000 AS INTEGER)`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
159
173
|
/**
|
|
160
174
|
* The migrator's own ledger, read by readiness to tell a database that is
|
|
161
175
|
* up but not yet migrated from one that is ready. Drizzle keeps it in a
|