@revojs/storage 0.3.8 → 0.3.9

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.
@@ -1,5 +1,5 @@
1
1
  import type { Awaitable, Primitive } from "revojs/shared";
2
- import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, type AppendToNullabilityMap, type AppendToSelection, type ColumnMeta, type Definition, type DeleteConstraintChange, type MigrationContext, type SelectMode, type Session, type Sql, type UpdateColumnChange } from "../index";
2
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, type AppendToNullabilityMap, type AppendToSelection, type ColumnMeta, type Definition, type DeleteConstraintChange, type MigrationContext, type SelectMode, type Session, Sql, type UpdateColumnChange } from "../index";
3
3
  export type IntegerMode = "number" | "timestamp" | "timestamp_ms" | "boolean";
4
4
  export type IntegerData<TMode> = TMode extends "timestamp" | "timestamp_ms" ? Date : TMode extends "boolean" ? boolean : number;
5
5
  export type TextMode = "text" | "json";
@@ -90,6 +90,10 @@ export declare function real(name: string): RealColumn;
90
90
  export declare function text<TMode extends TextMode = "text">(name: string, options?: TextOptions<TMode>): TextColumn<TMode>;
91
91
  export declare function unique(...columns: Array<Column>): SqliteUniqueConstraint;
92
92
  export declare function check(value: Sql): SqliteCheckConstraint;
93
+ export declare function id(name?: string): TextColumn<"text"> & Record<"notNull", never> & Record<"primaryKey", never> & Record<"default", never>;
94
+ export declare function timestamp(name: string): IntegerColumn<"timestamp_ms"> & Record<"notNull", never> & Record<"default", never>;
95
+ export declare function checkValues(column: Column, values: ReadonlyArray<string | number | boolean>): SqliteCheckConstraint;
96
+ export declare function checkJson(column: Column): SqliteCheckConstraint;
93
97
  export declare function primaryKey(...columns: Array<Column>): SqlitePrimaryKeyConstraint;
94
98
  export declare function foreignKey(columns: Array<Column>, foreignColumns: Array<Column>): SqliteForeignKeyConstraint;
95
99
  export declare function index(...columns: Array<Column>): SqliteIndex;
@@ -1,4 +1,4 @@
1
- import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, combine, sql } from "../index.js";
1
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Sql, Table, UniqueConstraint, UniqueIndex, UpdateStatement, combine, sql } from "../index.js";
2
2
  //#region src/protocols/sqlite.ts
3
3
  var SqliteColumn = class extends Column {
4
4
  type() {
@@ -201,6 +201,20 @@ function unique(...columns) {
201
201
  function check(value) {
202
202
  return new SqliteCheckConstraint(value);
203
203
  }
204
+ function id(name = "Id") {
205
+ return text(name).notNull().primaryKey().default(() => crypto.randomUUID());
206
+ }
207
+ function timestamp(name) {
208
+ return integer(name, { mode: "timestamp_ms" }).notNull().default(() => /* @__PURE__ */ new Date());
209
+ }
210
+ function checkValues(column, values) {
211
+ const literals = new Array();
212
+ for (const value of values) literals.push(typeof value === "string" ? `'${value.replaceAll("'", "''")}'` : String(Number(value)));
213
+ return check(new Sql(column, ` IN (${literals.join(", ")})`));
214
+ }
215
+ function checkJson(column) {
216
+ return check(column.$notNull ? sql`json_valid(${column})` : sql`${column} IS NULL OR json_valid(${column})`);
217
+ }
204
218
  function primaryKey(...columns) {
205
219
  return new SqlitePrimaryKeyConstraint(...columns);
206
220
  }
@@ -217,4 +231,4 @@ function table(name, columns, definitions) {
217
231
  return Object.assign(new SqliteTable(name, columns, definitions?.(columns) ?? []), columns);
218
232
  }
219
233
  //#endregion
220
- export { BlobColumn, IntegerColumn, NumericColumn, RealColumn, SqliteCheckConstraint, SqliteColumn, SqliteDatabase, SqliteDeleteStatement, SqliteForeignKeyConstraint, SqliteIndex, SqliteInsertStatement, SqliteMigration, SqlitePrimaryKeyConstraint, SqliteSelectStatement, SqliteTable, SqliteUniqueConstraint, SqliteUniqueIndex, SqliteUpdateStatement, TextColumn, blob, check, foreignKey, index, integer, numeric, primaryKey, real, table, text, unique, uniqueIndex };
234
+ export { BlobColumn, IntegerColumn, NumericColumn, RealColumn, SqliteCheckConstraint, SqliteColumn, SqliteDatabase, SqliteDeleteStatement, SqliteForeignKeyConstraint, SqliteIndex, SqliteInsertStatement, SqliteMigration, SqlitePrimaryKeyConstraint, SqliteSelectStatement, SqliteTable, SqliteUniqueConstraint, SqliteUniqueIndex, SqliteUpdateStatement, TextColumn, blob, check, checkJson, checkValues, foreignKey, id, index, integer, numeric, primaryKey, real, table, text, timestamp, unique, uniqueIndex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/storage",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,10 +37,10 @@
37
37
  "watch": "vite build --watch"
38
38
  },
39
39
  "dependencies": {
40
- "revojs": "0.3.8"
40
+ "revojs": "0.3.9"
41
41
  },
42
42
  "devDependencies": {
43
- "@revojs/tsconfig": "0.3.8"
43
+ "@revojs/tsconfig": "0.3.9"
44
44
  },
45
45
  "optionalDependencies": {
46
46
  "@cloudflare/workers-types": "^5.20261009.1",