@remit/drizzle-sqlite-schema 0.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/types.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { customType } from "drizzle-orm/sqlite-core";
2
+ import short from "short-uuid";
3
+
4
+ const translator = short(short.constants.uuid25Base36);
5
+
6
+ /** UUID column stored as text, reads/writes as base36 */
7
+ export const base36Uuid = customType<{
8
+ data: string;
9
+ driverData: string;
10
+ }>({
11
+ dataType: () => "text",
12
+ toDriver: (value: string): string => translator.toUUID(value),
13
+ fromDriver: (value: string): string => translator.fromUUID(value),
14
+ });
15
+
16
+ export function generateBase36Id(): string {
17
+ return translator.new();
18
+ }
19
+
20
+ export const nullableText = customType<{
21
+ data: string | undefined;
22
+ driverData: string | null;
23
+ }>({
24
+ dataType: () => "text",
25
+ fromDriver: (v) => v ?? undefined,
26
+ });
27
+
28
+ export const nullableInteger = customType<{
29
+ data: number | undefined;
30
+ driverData: number | null;
31
+ }>({
32
+ dataType: () => "integer",
33
+ fromDriver: (v) => v ?? undefined,
34
+ });
35
+
36
+ export const nullableReal = customType<{
37
+ data: number | undefined;
38
+ driverData: number | null;
39
+ }>({
40
+ dataType: () => "real",
41
+ fromDriver: (v) => v ?? undefined,
42
+ });