@space-arch/util-drizzle 1.7.0 → 2.0.1
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/README.md +6 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -21
- package/dist/lib/uuidv7.d.ts +21 -11
- package/dist/lib/uuidv7.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,20 +41,20 @@ const users = await db.select().from(usersTable);
|
|
|
41
41
|
|
|
42
42
|
### UUIDv7 Column Types
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
PostgreSQL `uuid` columns auto-filled with UUIDv7 on insert. Nullable by default — chain `.notNull()` / `.primaryKey()` as you would with drizzle's built-in `uuid()`.
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
47
|
import { pgTable } from 'drizzle-orm/pg-core';
|
|
48
|
-
import { uuidV7
|
|
48
|
+
import { uuidV7 } from '@space-arch/util-drizzle';
|
|
49
49
|
|
|
50
50
|
const users = pgTable('users', {
|
|
51
|
-
id:
|
|
52
|
-
|
|
51
|
+
id: uuidV7().primaryKey(), // PK, auto-filled on insert
|
|
52
|
+
tenantId: uuidV7('tenant_id').notNull(), // required FK
|
|
53
|
+
parentId: uuidV7('parent_id'), // nullable FK
|
|
53
54
|
});
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
- `uuidV7Nullable()` - Nullable without default value
|
|
57
|
+
The default is applied at insert time by the drizzle runtime — it does NOT emit a SQL `DEFAULT` clause in migrations. For a raw nullable uuid with no auto-default, use drizzle's built-in `uuid()` directly.
|
|
58
58
|
|
|
59
59
|
## Contributing
|
|
60
60
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("drizzle-orm/pg-core"),l=require("uuid"),y=(n,i)=>{let u=null;const r=()=>(u||(u=n(i())),u);return new Proxy({},{get(t,o){const e=r(),c=e[o];return typeof c=="function"?c.bind(e):c},getPrototypeOf(){const t=r();return Object.getPrototypeOf(t)},has(t,o){const e=r();return o in e},ownKeys(){const t=r();return Reflect.ownKeys(t)},getOwnPropertyDescriptor(t,o){const e=r();return Reflect.getOwnPropertyDescriptor(e,o)}})},s=d.customType({dataType:()=>"uuid"}),g=n=>(n===void 0?s():s(n)).$defaultFn(()=>l.v7());exports.lazyDrizzle=y;exports.uuidV7=g;
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
import { customType as
|
|
2
|
-
import { v7 as
|
|
3
|
-
const
|
|
1
|
+
import { customType as i } from "drizzle-orm/pg-core";
|
|
2
|
+
import { v7 as p } from "uuid";
|
|
3
|
+
const l = (n, d) => {
|
|
4
4
|
let u = null;
|
|
5
|
-
const
|
|
5
|
+
const r = () => (u || (u = n(d())), u);
|
|
6
6
|
return new Proxy({}, {
|
|
7
|
-
get(t,
|
|
8
|
-
const e =
|
|
7
|
+
get(t, o) {
|
|
8
|
+
const e = r(), c = e[o];
|
|
9
9
|
return typeof c == "function" ? c.bind(e) : c;
|
|
10
10
|
},
|
|
11
11
|
getPrototypeOf() {
|
|
12
|
-
const t =
|
|
12
|
+
const t = r();
|
|
13
13
|
return Object.getPrototypeOf(t);
|
|
14
14
|
},
|
|
15
|
-
has(t,
|
|
16
|
-
const e =
|
|
17
|
-
return
|
|
15
|
+
has(t, o) {
|
|
16
|
+
const e = r();
|
|
17
|
+
return o in e;
|
|
18
18
|
},
|
|
19
19
|
ownKeys() {
|
|
20
|
-
const t =
|
|
20
|
+
const t = r();
|
|
21
21
|
return Reflect.ownKeys(t);
|
|
22
22
|
},
|
|
23
|
-
getOwnPropertyDescriptor(t,
|
|
24
|
-
const e =
|
|
25
|
-
return Reflect.getOwnPropertyDescriptor(e,
|
|
23
|
+
getOwnPropertyDescriptor(t, o) {
|
|
24
|
+
const e = r();
|
|
25
|
+
return Reflect.getOwnPropertyDescriptor(e, o);
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
},
|
|
28
|
+
}, s = i({
|
|
29
29
|
dataType: () => "uuid"
|
|
30
|
-
})(
|
|
31
|
-
dataType: () => "uuid"
|
|
32
|
-
})(r);
|
|
30
|
+
}), b = (n) => (n === void 0 ? s() : s(n)).$defaultFn(() => p());
|
|
33
31
|
export {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
b as uuidV7Nullable
|
|
32
|
+
l as lazyDrizzle,
|
|
33
|
+
b as uuidV7
|
|
37
34
|
};
|
package/dist/lib/uuidv7.d.ts
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Drizzle column builder for a PostgreSQL `uuid` column auto-filled with a
|
|
3
|
+
* UUIDv7 on insert (via `uuid.v7()` through `$defaultFn`).
|
|
4
|
+
*
|
|
5
|
+
* Nullable by default — chain `.notNull()`, `.primaryKey()`, etc. as with
|
|
6
|
+
* drizzle's built-in `uuid()`.
|
|
7
|
+
*
|
|
8
|
+
* The default is applied at insert time in the application layer; it does
|
|
9
|
+
* NOT emit a SQL `DEFAULT` clause in migrations.
|
|
10
|
+
*
|
|
11
|
+
* Nullable-FK caveat: omitting the field on insert triggers `$defaultFn` and
|
|
12
|
+
* produces a UUID pointing nowhere. For a truly raw nullable uuid, use
|
|
13
|
+
* drizzle's built-in `uuid()` from `drizzle-orm/pg-core`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const users = pgTable('users', {
|
|
17
|
+
* id: uuidV7().primaryKey(), // PK, auto-filled
|
|
18
|
+
* tenantId: uuidV7('tenant_id').notNull(), // required FK
|
|
19
|
+
* parentId: uuidV7('parent_id'), // nullable FK
|
|
20
|
+
* });
|
|
3
21
|
*/
|
|
4
|
-
export declare const uuidV7: (name
|
|
5
|
-
data: string;
|
|
6
|
-
notNull: true;
|
|
7
|
-
default: true;
|
|
8
|
-
}>>>>>;
|
|
9
|
-
/**
|
|
10
|
-
* A custom type for UUIDv7 columns. Nullable
|
|
11
|
-
*/
|
|
12
|
-
export declare const uuidV7Nullable: (name: string) => import('drizzle-orm/pg-core').PgCustomColumnBuilder<{
|
|
22
|
+
export declare const uuidV7: (name?: string) => import('drizzle-orm').HasRuntimeDefault<import('drizzle-orm').HasDefault<import('drizzle-orm/pg-core').PgCustomColumnBuilder<{
|
|
13
23
|
name: string;
|
|
14
24
|
dataType: "custom";
|
|
15
25
|
columnType: "PgCustomColumn";
|
|
16
26
|
data: string;
|
|
17
27
|
driverParam: unknown;
|
|
18
28
|
enumValues: undefined;
|
|
19
|
-
}
|
|
29
|
+
}>>>;
|
|
20
30
|
//# sourceMappingURL=uuidv7.d.ts.map
|
package/dist/lib/uuidv7.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuidv7.d.ts","sourceRoot":"","sources":["../../src/lib/uuidv7.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uuidv7.d.ts","sourceRoot":"","sources":["../../src/lib/uuidv7.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM;;;;;;;IAC2C,CAAC"}
|