drizzle-orm 0.29.1 → 0.29.2-1d1e96d
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 +19 -7
- package/aws-data-api/common/index.cjs +14 -1
- package/aws-data-api/common/index.cjs.map +1 -1
- package/aws-data-api/common/index.js +14 -1
- package/aws-data-api/common/index.js.map +1 -1
- package/expo-sqlite/driver.cjs +56 -0
- package/expo-sqlite/driver.cjs.map +1 -0
- package/expo-sqlite/driver.d.cts +5 -0
- package/expo-sqlite/driver.d.ts +5 -0
- package/expo-sqlite/driver.js +35 -0
- package/expo-sqlite/driver.js.map +1 -0
- package/expo-sqlite/index.cjs +25 -0
- package/expo-sqlite/index.cjs.map +1 -0
- package/expo-sqlite/index.d.cts +2 -0
- package/expo-sqlite/index.d.ts +2 -0
- package/expo-sqlite/index.js +3 -0
- package/expo-sqlite/index.js.map +1 -0
- package/expo-sqlite/migrator.cjs +92 -0
- package/expo-sqlite/migrator.cjs.map +1 -0
- package/expo-sqlite/migrator.d.cts +29 -0
- package/expo-sqlite/migrator.d.ts +29 -0
- package/expo-sqlite/migrator.js +67 -0
- package/expo-sqlite/migrator.js.map +1 -0
- package/expo-sqlite/session.cjs +134 -0
- package/expo-sqlite/session.cjs.map +1 -0
- package/expo-sqlite/session.d.cts +46 -0
- package/expo-sqlite/session.d.ts +46 -0
- package/expo-sqlite/session.js +111 -0
- package/expo-sqlite/session.js.map +1 -0
- package/package.json +55 -1
- package/pg-core/utils/array.cjs +2 -2
- package/pg-core/utils/array.cjs.map +1 -1
- package/pg-core/utils/array.js +2 -2
- package/pg-core/utils/array.js.map +1 -1
- package/sql/expressions/conditions.cjs +2 -2
- package/sql/expressions/conditions.cjs.map +1 -1
- package/sql/expressions/conditions.js +2 -2
- package/sql/expressions/conditions.js.map +1 -1
- package/utils.cjs +2 -0
- package/utils.cjs.map +1 -1
- package/utils.js +2 -0
- package/utils.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./misc/readme/logo-github-dark.svg#gh-dark-mode-only" />
|
|
3
|
+
<img src="./misc/readme/logo-github-light.svg#gh-light-mode-only" />
|
|
4
|
+
</div>
|
|
5
|
+
<h4 align="center">
|
|
6
|
+
<a href="https://oramasearch.com?utm_source=github">Website</a> •
|
|
7
|
+
<a href="https://oramasearch.com/blog?utm_source=github">Blog</a> •
|
|
8
|
+
<a href="https://docs.oramasearch.com?utm_source=github">Documentation</a> •
|
|
9
|
+
<a href="https://orama.to/slack">Slack</a>
|
|
10
|
+
</h4>
|
|
11
|
+
<br />
|
|
12
|
+
|
|
1
13
|
<div align="center">
|
|
2
14
|
<h1>Drizzle ORM <a href=""><img alt="npm" src="https://img.shields.io/npm/v/drizzle-orm?label="></a></h1>
|
|
3
15
|
<img alt="npm" src="https://img.shields.io/npm/dm/drizzle-orm">
|
|
4
16
|
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/drizzle-orm">
|
|
5
17
|
<a href="https://discord.gg/yfjTbVXMW4" target="_blank"><img alt="Discord" src="https://img.shields.io/discord/1043890932593987624?label=Discord"></a>
|
|
6
18
|
<img alt="License" src="https://img.shields.io/npm/l/drizzle-orm">
|
|
7
|
-
|
|
19
|
+
|
|
8
20
|
<hr />
|
|
9
21
|
</div>
|
|
10
22
|
|
|
@@ -35,13 +47,13 @@ Check the full documentation on [the website](https://orm.drizzle.team)
|
|
|
35
47
|
| PostgreSQL | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
|
|
36
48
|
| MySQL | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
|
|
37
49
|
| SQLite | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
|
|
38
|
-
| Cloudflare D1 | ✅ | [Docs](https://driz.
|
|
50
|
+
| Cloudflare D1 | ✅ | [Docs](https://driz.link/docs-d1) | [Website](https://developers.cloudflare.com/d1) |
|
|
39
51
|
| libSQL | ✅ | [Docs](/examples/libsql/README.md) | [Website](https://libsql.org) |
|
|
40
|
-
| Turso | ✅ | [Docs](https://driz.
|
|
41
|
-
| PlanetScale | ✅ | [Docs](https://driz.
|
|
42
|
-
| Neon | ✅ | [Docs](https://driz.
|
|
43
|
-
| Vercel Postgres | ✅ | [Docs](https://driz.
|
|
44
|
-
| Supabase | ✅ | [Docs](https://driz.
|
|
52
|
+
| Turso | ✅ | [Docs](https://driz.link/docs-turso) | [Website](https://turso.tech) |
|
|
53
|
+
| PlanetScale | ✅ | [Docs](https://driz.link/docs-planetscale) | [Website](https://planetscale.com/) |
|
|
54
|
+
| Neon | ✅ | [Docs](https://driz.link/docs-neon) | [Website](https://neon.tech/) |
|
|
55
|
+
| Vercel Postgres | ✅ | [Docs](https://driz.link/docs-vercel-postgres) | [Website](https://vercel.com/docs/storage/vercel-postgres/quickstart) |
|
|
56
|
+
| Supabase | ✅ | [Docs](https://driz.link/docs-supabase) | [Website](https://supabase.com) |
|
|
45
57
|
| DynamoDB | ⏳ | | |
|
|
46
58
|
| MS SQL | ⏳ | | |
|
|
47
59
|
| CockroachDB | ⏳ | | |
|
|
@@ -71,7 +71,20 @@ function toValueParam(value, typings) {
|
|
|
71
71
|
if (value === null) {
|
|
72
72
|
response.value = { isNull: true };
|
|
73
73
|
} else if (typeof value === "string") {
|
|
74
|
-
|
|
74
|
+
switch (response.typeHint) {
|
|
75
|
+
case import_client_rds_data.TypeHint.DATE: {
|
|
76
|
+
response.value = { stringValue: value.split("T")[0] };
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case import_client_rds_data.TypeHint.TIMESTAMP: {
|
|
80
|
+
response.value = { stringValue: value.replace("T", " ").replace("Z", "") };
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
default: {
|
|
84
|
+
response.value = { stringValue: value };
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
75
88
|
} else if (typeof value === "number" && Number.isInteger(value)) {
|
|
76
89
|
response.value = { longValue: value };
|
|
77
90
|
} else if (typeof value === "number" && !Number.isInteger(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/aws-data-api/common/index.ts"],"sourcesContent":["import type { Field } from '@aws-sdk/client-rds-data';\nimport { TypeHint } from '@aws-sdk/client-rds-data';\nimport type { QueryTypingsValue } from '~/sql/sql.ts';\n\nexport function getValueFromDataApi(field: Field) {\n\tif (field.stringValue !== undefined) {\n\t\treturn field.stringValue;\n\t} else if (field.booleanValue !== undefined) {\n\t\treturn field.booleanValue;\n\t} else if (field.doubleValue !== undefined) {\n\t\treturn field.doubleValue;\n\t} else if (field.isNull !== undefined) {\n\t\treturn null;\n\t} else if (field.longValue !== undefined) {\n\t\treturn field.longValue;\n\t} else if (field.blobValue !== undefined) {\n\t\treturn field.blobValue;\n\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t} else if (field.arrayValue !== undefined) {\n\t\tif (field.arrayValue.stringValues !== undefined) {\n\t\t\treturn field.arrayValue.stringValues;\n\t\t}\n\t\tthrow new Error('Unknown array type');\n\t} else {\n\t\tthrow new Error('Unknown type');\n\t}\n}\n\nexport function typingsToAwsTypeHint(typings?: QueryTypingsValue): TypeHint | undefined {\n\tif (typings === 'date') {\n\t\treturn TypeHint.DATE;\n\t} else if (typings === 'decimal') {\n\t\treturn TypeHint.DECIMAL;\n\t} else if (typings === 'json') {\n\t\treturn TypeHint.JSON;\n\t} else if (typings === 'time') {\n\t\treturn TypeHint.TIME;\n\t} else if (typings === 'timestamp') {\n\t\treturn TypeHint.TIMESTAMP;\n\t} else if (typings === 'uuid') {\n\t\treturn TypeHint.UUID;\n\t} else {\n\t\treturn undefined;\n\t}\n}\n\nexport function toValueParam(value: any, typings?: QueryTypingsValue): { value: Field; typeHint?: TypeHint } {\n\tconst response: { value: Field; typeHint?: TypeHint } = {\n\t\tvalue: {} as any,\n\t\ttypeHint: typingsToAwsTypeHint(typings),\n\t};\n\n\tif (value === null) {\n\t\tresponse.value = { isNull: true };\n\t} else if (typeof value === 'string') {\n\t\
|
|
1
|
+
{"version":3,"sources":["../../../src/aws-data-api/common/index.ts"],"sourcesContent":["import type { Field } from '@aws-sdk/client-rds-data';\nimport { TypeHint } from '@aws-sdk/client-rds-data';\nimport type { QueryTypingsValue } from '~/sql/sql.ts';\n\nexport function getValueFromDataApi(field: Field) {\n\tif (field.stringValue !== undefined) {\n\t\treturn field.stringValue;\n\t} else if (field.booleanValue !== undefined) {\n\t\treturn field.booleanValue;\n\t} else if (field.doubleValue !== undefined) {\n\t\treturn field.doubleValue;\n\t} else if (field.isNull !== undefined) {\n\t\treturn null;\n\t} else if (field.longValue !== undefined) {\n\t\treturn field.longValue;\n\t} else if (field.blobValue !== undefined) {\n\t\treturn field.blobValue;\n\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t} else if (field.arrayValue !== undefined) {\n\t\tif (field.arrayValue.stringValues !== undefined) {\n\t\t\treturn field.arrayValue.stringValues;\n\t\t}\n\t\tthrow new Error('Unknown array type');\n\t} else {\n\t\tthrow new Error('Unknown type');\n\t}\n}\n\nexport function typingsToAwsTypeHint(typings?: QueryTypingsValue): TypeHint | undefined {\n\tif (typings === 'date') {\n\t\treturn TypeHint.DATE;\n\t} else if (typings === 'decimal') {\n\t\treturn TypeHint.DECIMAL;\n\t} else if (typings === 'json') {\n\t\treturn TypeHint.JSON;\n\t} else if (typings === 'time') {\n\t\treturn TypeHint.TIME;\n\t} else if (typings === 'timestamp') {\n\t\treturn TypeHint.TIMESTAMP;\n\t} else if (typings === 'uuid') {\n\t\treturn TypeHint.UUID;\n\t} else {\n\t\treturn undefined;\n\t}\n}\n\nexport function toValueParam(value: any, typings?: QueryTypingsValue): { value: Field; typeHint?: TypeHint } {\n\tconst response: { value: Field; typeHint?: TypeHint } = {\n\t\tvalue: {} as any,\n\t\ttypeHint: typingsToAwsTypeHint(typings),\n\t};\n\n\tif (value === null) {\n\t\tresponse.value = { isNull: true };\n\t} else if (typeof value === 'string') {\n\t\tswitch (response.typeHint) {\n\t\t\tcase TypeHint.DATE: {\n\t\t\t\tresponse.value = { stringValue: value.split('T')[0]! };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TypeHint.TIMESTAMP: {\n\t\t\t\tresponse.value = { stringValue: value.replace('T', ' ').replace('Z', '') };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tresponse.value = { stringValue: value };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t} else if (typeof value === 'number' && Number.isInteger(value)) {\n\t\tresponse.value = { longValue: value };\n\t} else if (typeof value === 'number' && !Number.isInteger(value)) {\n\t\tresponse.value = { doubleValue: value };\n\t} else if (typeof value === 'boolean') {\n\t\tresponse.value = { booleanValue: value };\n\t} else if (value instanceof Date) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t// TODO: check if this clause is needed? Seems like date value always comes as string\n\t\tresponse.value = { stringValue: value.toISOString().replace('T', ' ').replace('Z', '') };\n\t} else {\n\t\tthrow new Error(`Unknown type for ${value}`);\n\t}\n\n\treturn response;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAAyB;AAGlB,SAAS,oBAAoB,OAAc;AACjD,MAAI,MAAM,gBAAgB,QAAW;AACpC,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,iBAAiB,QAAW;AAC5C,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,gBAAgB,QAAW;AAC3C,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,WAAW,QAAW;AACtC,WAAO;AAAA,EACR,WAAW,MAAM,cAAc,QAAW;AACzC,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,cAAc,QAAW;AACzC,WAAO,MAAM;AAAA,EAEd,WAAW,MAAM,eAAe,QAAW;AAC1C,QAAI,MA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YAAY,CAAC,OAAO,UAAU,KAAK,GAAG;AACjE,aAAS,QAAQ,EAAE,aAAa,MAAM;AAAA,EACvC,WAAW,OAAO,UAAU,WAAW;AACtC,aAAS,QAAQ,EAAE,cAAc,MAAM;AAAA,EACxC,WAAW,iBAAiB,MAAM;AAEjC,aAAS,QAAQ,EAAE,aAAa,MAAM,YAAY,EAAE,QAAQ,KAAK,GAAG,EAAE,QAAQ,KAAK,EAAE,EAAE;AAAA,EACxF,OAAO;AACN,UAAM,IAAI,MAAM,oBAAoB,KAAK,EAAE;AAAA,EAC5C;AAEA,SAAO;AACR;","names":[]}
|
|
@@ -46,7 +46,20 @@ function toValueParam(value, typings) {
|
|
|
46
46
|
if (value === null) {
|
|
47
47
|
response.value = { isNull: true };
|
|
48
48
|
} else if (typeof value === "string") {
|
|
49
|
-
|
|
49
|
+
switch (response.typeHint) {
|
|
50
|
+
case TypeHint.DATE: {
|
|
51
|
+
response.value = { stringValue: value.split("T")[0] };
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case TypeHint.TIMESTAMP: {
|
|
55
|
+
response.value = { stringValue: value.replace("T", " ").replace("Z", "") };
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
response.value = { stringValue: value };
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
} else if (typeof value === "number" && Number.isInteger(value)) {
|
|
51
64
|
response.value = { longValue: value };
|
|
52
65
|
} else if (typeof value === "number" && !Number.isInteger(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/aws-data-api/common/index.ts"],"sourcesContent":["import type { Field } from '@aws-sdk/client-rds-data';\nimport { TypeHint } from '@aws-sdk/client-rds-data';\nimport type { QueryTypingsValue } from '~/sql/sql.ts';\n\nexport function getValueFromDataApi(field: Field) {\n\tif (field.stringValue !== undefined) {\n\t\treturn field.stringValue;\n\t} else if (field.booleanValue !== undefined) {\n\t\treturn field.booleanValue;\n\t} else if (field.doubleValue !== undefined) {\n\t\treturn field.doubleValue;\n\t} else if (field.isNull !== undefined) {\n\t\treturn null;\n\t} else if (field.longValue !== undefined) {\n\t\treturn field.longValue;\n\t} else if (field.blobValue !== undefined) {\n\t\treturn field.blobValue;\n\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t} else if (field.arrayValue !== undefined) {\n\t\tif (field.arrayValue.stringValues !== undefined) {\n\t\t\treturn field.arrayValue.stringValues;\n\t\t}\n\t\tthrow new Error('Unknown array type');\n\t} else {\n\t\tthrow new Error('Unknown type');\n\t}\n}\n\nexport function typingsToAwsTypeHint(typings?: QueryTypingsValue): TypeHint | undefined {\n\tif (typings === 'date') {\n\t\treturn TypeHint.DATE;\n\t} else if (typings === 'decimal') {\n\t\treturn TypeHint.DECIMAL;\n\t} else if (typings === 'json') {\n\t\treturn TypeHint.JSON;\n\t} else if (typings === 'time') {\n\t\treturn TypeHint.TIME;\n\t} else if (typings === 'timestamp') {\n\t\treturn TypeHint.TIMESTAMP;\n\t} else if (typings === 'uuid') {\n\t\treturn TypeHint.UUID;\n\t} else {\n\t\treturn undefined;\n\t}\n}\n\nexport function toValueParam(value: any, typings?: QueryTypingsValue): { value: Field; typeHint?: TypeHint } {\n\tconst response: { value: Field; typeHint?: TypeHint } = {\n\t\tvalue: {} as any,\n\t\ttypeHint: typingsToAwsTypeHint(typings),\n\t};\n\n\tif (value === null) {\n\t\tresponse.value = { isNull: true };\n\t} else if (typeof value === 'string') {\n\t\
|
|
1
|
+
{"version":3,"sources":["../../../src/aws-data-api/common/index.ts"],"sourcesContent":["import type { Field } from '@aws-sdk/client-rds-data';\nimport { TypeHint } from '@aws-sdk/client-rds-data';\nimport type { QueryTypingsValue } from '~/sql/sql.ts';\n\nexport function getValueFromDataApi(field: Field) {\n\tif (field.stringValue !== undefined) {\n\t\treturn field.stringValue;\n\t} else if (field.booleanValue !== undefined) {\n\t\treturn field.booleanValue;\n\t} else if (field.doubleValue !== undefined) {\n\t\treturn field.doubleValue;\n\t} else if (field.isNull !== undefined) {\n\t\treturn null;\n\t} else if (field.longValue !== undefined) {\n\t\treturn field.longValue;\n\t} else if (field.blobValue !== undefined) {\n\t\treturn field.blobValue;\n\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t} else if (field.arrayValue !== undefined) {\n\t\tif (field.arrayValue.stringValues !== undefined) {\n\t\t\treturn field.arrayValue.stringValues;\n\t\t}\n\t\tthrow new Error('Unknown array type');\n\t} else {\n\t\tthrow new Error('Unknown type');\n\t}\n}\n\nexport function typingsToAwsTypeHint(typings?: QueryTypingsValue): TypeHint | undefined {\n\tif (typings === 'date') {\n\t\treturn TypeHint.DATE;\n\t} else if (typings === 'decimal') {\n\t\treturn TypeHint.DECIMAL;\n\t} else if (typings === 'json') {\n\t\treturn TypeHint.JSON;\n\t} else if (typings === 'time') {\n\t\treturn TypeHint.TIME;\n\t} else if (typings === 'timestamp') {\n\t\treturn TypeHint.TIMESTAMP;\n\t} else if (typings === 'uuid') {\n\t\treturn TypeHint.UUID;\n\t} else {\n\t\treturn undefined;\n\t}\n}\n\nexport function toValueParam(value: any, typings?: QueryTypingsValue): { value: Field; typeHint?: TypeHint } {\n\tconst response: { value: Field; typeHint?: TypeHint } = {\n\t\tvalue: {} as any,\n\t\ttypeHint: typingsToAwsTypeHint(typings),\n\t};\n\n\tif (value === null) {\n\t\tresponse.value = { isNull: true };\n\t} else if (typeof value === 'string') {\n\t\tswitch (response.typeHint) {\n\t\t\tcase TypeHint.DATE: {\n\t\t\t\tresponse.value = { stringValue: value.split('T')[0]! };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TypeHint.TIMESTAMP: {\n\t\t\t\tresponse.value = { stringValue: value.replace('T', ' ').replace('Z', '') };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tresponse.value = { stringValue: value };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t} else if (typeof value === 'number' && Number.isInteger(value)) {\n\t\tresponse.value = { longValue: value };\n\t} else if (typeof value === 'number' && !Number.isInteger(value)) {\n\t\tresponse.value = { doubleValue: value };\n\t} else if (typeof value === 'boolean') {\n\t\tresponse.value = { booleanValue: value };\n\t} else if (value instanceof Date) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t// TODO: check if this clause is needed? Seems like date value always comes as string\n\t\tresponse.value = { stringValue: value.toISOString().replace('T', ' ').replace('Z', '') };\n\t} else {\n\t\tthrow new Error(`Unknown type for ${value}`);\n\t}\n\n\treturn response;\n}\n"],"mappings":"AACA,SAAS,gBAAgB;AAGlB,SAAS,oBAAoB,OAAc;AACjD,MAAI,MAAM,gBAAgB,QAAW;AACpC,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,iBAAiB,QAAW;AAC5C,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,gBAAgB,QAAW;AAC3C,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,WAAW,QAAW;AACtC,WAAO;AAAA,EACR,WAAW,MAAM,cAAc,QAAW;AACzC,WAAO,MAAM;AAAA,EACd,WAAW,MAAM,cAAc,QAAW;AACzC,WAAO,MAAM;AAAA,EAEd,WAAW,MAAM,eAAe,QAAW;AAC1C,QAAI,MAAM,WAAW,iBAAiB,QAAW;AAChD,aAAO,MAAM,WAAW;AAAA,IACzB;AACA,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC,OAAO;AACN,UAAM,IAAI,MAAM,cAAc;AAAA,EAC/B;AACD;AAEO,SAAS,qBAAqB,SAAmD;AACvF,MAAI,YAAY,QAAQ;AACvB,WAAO,SAAS;AAAA,EACjB,WAAW,YAAY,WAAW;AACjC,WAAO,SAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,SAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,SAAS;AAAA,EACjB,WAAW,YAAY,aAAa;AACnC,WAAO,SAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,S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esc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var driver_exports = {};
|
|
20
|
+
__export(driver_exports, {
|
|
21
|
+
drizzle: () => drizzle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(driver_exports);
|
|
24
|
+
var import_logger = require("../logger.cjs");
|
|
25
|
+
var import_relations = require("../relations.cjs");
|
|
26
|
+
var import_db = require("../sqlite-core/db.cjs");
|
|
27
|
+
var import_dialect = require("../sqlite-core/dialect.cjs");
|
|
28
|
+
var import_session = require("./session.cjs");
|
|
29
|
+
function drizzle(client, config = {}) {
|
|
30
|
+
const dialect = new import_dialect.SQLiteSyncDialect();
|
|
31
|
+
let logger;
|
|
32
|
+
if (config.logger === true) {
|
|
33
|
+
logger = new import_logger.DefaultLogger();
|
|
34
|
+
} else if (config.logger !== false) {
|
|
35
|
+
logger = config.logger;
|
|
36
|
+
}
|
|
37
|
+
let schema;
|
|
38
|
+
if (config.schema) {
|
|
39
|
+
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
|
|
40
|
+
config.schema,
|
|
41
|
+
import_relations.createTableRelationsHelpers
|
|
42
|
+
);
|
|
43
|
+
schema = {
|
|
44
|
+
fullSchema: config.schema,
|
|
45
|
+
schema: tablesConfig.tables,
|
|
46
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const session = new import_session.ExpoSQLiteSession(client, dialect, schema, { logger });
|
|
50
|
+
return new import_db.BaseSQLiteDatabase("sync", dialect, session, schema);
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
drizzle
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=driver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/driver.ts"],"sourcesContent":["import type { SQLiteDatabase, SQLiteRunResult } from 'expo-sqlite/next';\nimport { DefaultLogger } from '~/logger.ts';\nimport {\n createTableRelationsHelpers,\n extractTablesRelationalConfig,\n type RelationalSchemaConfig,\n type TablesRelationalConfig,\n} from '~/relations.ts';\nimport { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';\nimport { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleConfig } from '~/utils.ts';\nimport { ExpoSQLiteSession } from './session.ts';\n\nexport type ExpoSQLiteDatabase<\n TSchema extends Record<string, unknown> = Record<string, never>,\n> = BaseSQLiteDatabase<'sync', SQLiteRunResult, TSchema>;\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n client: SQLiteDatabase,\n config: DrizzleConfig<TSchema> = {},\n): ExpoSQLiteDatabase<TSchema> {\n const dialect = new SQLiteSyncDialect();\n let logger;\n if (config.logger === true) {\n logger = new DefaultLogger();\n } else if (config.logger !== false) {\n logger = config.logger;\n }\n\n let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n if (config.schema) {\n const tablesConfig = extractTablesRelationalConfig(\n config.schema,\n createTableRelationsHelpers,\n );\n schema = {\n fullSchema: config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap,\n };\n }\n\n const session = new ExpoSQLiteSession(client, dialect, schema, { logger });\n return new BaseSQLiteDatabase('sync', dialect, session, schema) as ExpoSQLiteDatabase<TSchema>;\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,uBAKO;AACP,gBAAmC;AACnC,qBAAkC;AAElC,qBAAkC;AAM3B,SAAS,QACZ,QACA,SAAiC,CAAC,GACP;AAC3B,QAAM,UAAU,IAAI,iCAAkB;AACtC,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AACxB,aAAS,IAAI,4BAAc;AAAA,EAC/B,WAAW,OAAO,WAAW,OAAO;AAChC,aAAS,OAAO;AAAA,EACpB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AACf,UAAM,mBAAe;AAAA,MACjB,OAAO;AAAA,MACP;AAAA,IACJ;AACA,aAAS;AAAA,MACL,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAChC;AAAA,EACJ;AAEA,QAAM,UAAU,IAAI,iCAAkB,QAAQ,SAAS,QAAQ,EAAE,OAAO,CAAC;AACzE,SAAO,IAAI,6BAAmB,QAAQ,SAAS,SAAS,MAAM;AAClE;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SQLiteDatabase, SQLiteRunResult } from 'expo-sqlite/next';
|
|
2
|
+
import { BaseSQLiteDatabase } from "../sqlite-core/db.cjs";
|
|
3
|
+
import type { DrizzleConfig } from "../utils.cjs";
|
|
4
|
+
export type ExpoSQLiteDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = BaseSQLiteDatabase<'sync', SQLiteRunResult, TSchema>;
|
|
5
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: SQLiteDatabase, config?: DrizzleConfig<TSchema>): ExpoSQLiteDatabase<TSchema>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SQLiteDatabase, SQLiteRunResult } from 'expo-sqlite/next';
|
|
2
|
+
import { BaseSQLiteDatabase } from "../sqlite-core/db.js";
|
|
3
|
+
import type { DrizzleConfig } from "../utils.js";
|
|
4
|
+
export type ExpoSQLiteDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = BaseSQLiteDatabase<'sync', SQLiteRunResult, TSchema>;
|
|
5
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: SQLiteDatabase, config?: DrizzleConfig<TSchema>): ExpoSQLiteDatabase<TSchema>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DefaultLogger } from "../logger.js";
|
|
2
|
+
import {
|
|
3
|
+
createTableRelationsHelpers,
|
|
4
|
+
extractTablesRelationalConfig
|
|
5
|
+
} from "../relations.js";
|
|
6
|
+
import { BaseSQLiteDatabase } from "../sqlite-core/db.js";
|
|
7
|
+
import { SQLiteSyncDialect } from "../sqlite-core/dialect.js";
|
|
8
|
+
import { ExpoSQLiteSession } from "./session.js";
|
|
9
|
+
function drizzle(client, config = {}) {
|
|
10
|
+
const dialect = new SQLiteSyncDialect();
|
|
11
|
+
let logger;
|
|
12
|
+
if (config.logger === true) {
|
|
13
|
+
logger = new DefaultLogger();
|
|
14
|
+
} else if (config.logger !== false) {
|
|
15
|
+
logger = config.logger;
|
|
16
|
+
}
|
|
17
|
+
let schema;
|
|
18
|
+
if (config.schema) {
|
|
19
|
+
const tablesConfig = extractTablesRelationalConfig(
|
|
20
|
+
config.schema,
|
|
21
|
+
createTableRelationsHelpers
|
|
22
|
+
);
|
|
23
|
+
schema = {
|
|
24
|
+
fullSchema: config.schema,
|
|
25
|
+
schema: tablesConfig.tables,
|
|
26
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const session = new ExpoSQLiteSession(client, dialect, schema, { logger });
|
|
30
|
+
return new BaseSQLiteDatabase("sync", dialect, session, schema);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
drizzle
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/driver.ts"],"sourcesContent":["import type { SQLiteDatabase, SQLiteRunResult } from 'expo-sqlite/next';\nimport { DefaultLogger } from '~/logger.ts';\nimport {\n createTableRelationsHelpers,\n extractTablesRelationalConfig,\n type RelationalSchemaConfig,\n type TablesRelationalConfig,\n} from '~/relations.ts';\nimport { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';\nimport { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleConfig } from '~/utils.ts';\nimport { ExpoSQLiteSession } from './session.ts';\n\nexport type ExpoSQLiteDatabase<\n TSchema extends Record<string, unknown> = Record<string, never>,\n> = BaseSQLiteDatabase<'sync', SQLiteRunResult, TSchema>;\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n client: SQLiteDatabase,\n config: DrizzleConfig<TSchema> = {},\n): ExpoSQLiteDatabase<TSchema> {\n const dialect = new SQLiteSyncDialect();\n let logger;\n if (config.logger === true) {\n logger = new DefaultLogger();\n } else if (config.logger !== false) {\n logger = config.logger;\n }\n\n let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n if (config.schema) {\n const tablesConfig = extractTablesRelationalConfig(\n config.schema,\n createTableRelationsHelpers,\n );\n schema = {\n fullSchema: config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap,\n };\n }\n\n const session = new ExpoSQLiteSession(client, dialect, schema, { logger });\n return new BaseSQLiteDatabase('sync', dialect, session, schema) as ExpoSQLiteDatabase<TSchema>;\n}"],"mappings":"AACA,SAAS,qBAAqB;AAC9B;AAAA,EACI;AAAA,EACA;AAAA,OAGG;AACP,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAElC,SAAS,yBAAyB;AAM3B,SAAS,QACZ,QACA,SAAiC,CAAC,GACP;AAC3B,QAAM,UAAU,IAAI,kBAAkB;AACtC,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AACxB,aAAS,IAAI,cAAc;AAAA,EAC/B,WAAW,OAAO,WAAW,OAAO;AAChC,aAAS,OAAO;AAAA,EACpB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AACf,UAAM,eAAe;AAAA,MACjB,OAAO;AAAA,MACP;AAAA,IACJ;AACA,aAAS;AAAA,MACL,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAChC;AAAA,EACJ;AAEA,QAAM,UAAU,IAAI,kBAAkB,QAAQ,SAAS,QAAQ,EAAE,OAAO,CAAC;AACzE,SAAO,IAAI,mBAAmB,QAAQ,SAAS,SAAS,MAAM;AAClE;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var expo_sqlite_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(expo_sqlite_exports);
|
|
18
|
+
__reExport(expo_sqlite_exports, require("./driver.cjs"), module.exports);
|
|
19
|
+
__reExport(expo_sqlite_exports, require("./session.cjs"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./driver.cjs"),
|
|
23
|
+
...require("./session.cjs")
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,wBAAd;AACA,gCAAc,yBADd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var migrator_exports = {};
|
|
20
|
+
__export(migrator_exports, {
|
|
21
|
+
migrate: () => migrate,
|
|
22
|
+
useMigrations: () => useMigrations
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(migrator_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
async function readMigrationFiles({ journal, migrations }) {
|
|
27
|
+
const migrationQueries = [];
|
|
28
|
+
for await (const journalEntry of journal.entries) {
|
|
29
|
+
const query = migrations[`m${journalEntry.idx.toString().padStart(4, "0")}`];
|
|
30
|
+
if (!query) {
|
|
31
|
+
throw new Error(`Missing migration: ${journalEntry.tag}`);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
35
|
+
return it;
|
|
36
|
+
});
|
|
37
|
+
migrationQueries.push({
|
|
38
|
+
sql: result,
|
|
39
|
+
bps: journalEntry.breakpoints,
|
|
40
|
+
folderMillis: journalEntry.when,
|
|
41
|
+
hash: ""
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return migrationQueries;
|
|
48
|
+
}
|
|
49
|
+
async function migrate(db, config) {
|
|
50
|
+
const migrations = await readMigrationFiles(config);
|
|
51
|
+
return db.dialect.migrate(migrations, db.session);
|
|
52
|
+
}
|
|
53
|
+
const useMigrations = (db, migrations) => {
|
|
54
|
+
const initialState = {
|
|
55
|
+
success: false,
|
|
56
|
+
error: void 0
|
|
57
|
+
};
|
|
58
|
+
const fetchReducer = (state2, action) => {
|
|
59
|
+
switch (action.type) {
|
|
60
|
+
case "migrating": {
|
|
61
|
+
return { ...initialState };
|
|
62
|
+
}
|
|
63
|
+
case "migrated": {
|
|
64
|
+
return { ...initialState, success: action.payload };
|
|
65
|
+
}
|
|
66
|
+
case "error": {
|
|
67
|
+
return { ...initialState, error: action.payload };
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
return state2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const [state, dispatch] = (0, import_react.useReducer)(fetchReducer, initialState);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
dispatch({ type: "migrating" });
|
|
77
|
+
try {
|
|
78
|
+
migrate(db, migrations).then(() => {
|
|
79
|
+
dispatch({ type: "migrated", payload: true });
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
dispatch({ type: "error", payload: error });
|
|
83
|
+
}
|
|
84
|
+
}, []);
|
|
85
|
+
return state;
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
migrate,
|
|
90
|
+
useMigrations
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=migrator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from \"react\";\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n journal: {\n entries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n };\n migrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n const migrationQueries: MigrationMeta[] = [];\n\n for await (const journalEntry of journal.entries) {\n const query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n if (!query) {\n throw new Error(`Missing migration: ${journalEntry.tag}`);\n }\n\n try {\n const result = query.split('--> statement-breakpoint').map((it) => {\n return it;\n });\n\n migrationQueries.push({\n sql: result,\n bps: journalEntry.breakpoints,\n folderMillis: journalEntry.when,\n hash: '',\n });\n } catch {\n throw new Error(`Failed to parse migration: ${journalEntry.tag}`);\n }\n }\n\n return migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n db: ExpoSQLiteDatabase<TSchema>,\n config: MigrationConfig,\n) {\n const migrations = await readMigrationFiles(config);\n return db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error }\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t}\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState }\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload }\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state\n\t\t\t}\n\t\t}\n\t}\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })\n\t\ttry {\n\t\t\tmigrate(db, migrations as any).then(() => {\n\t\t\t\tdispatch({ type: 'migrated', payload: true })\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tdispatch({ type: 'error', payload: error as Error })\n\t\t}\n\t}, []);\n\n\treturn state;\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAWtC,eAAe,mBAAmB,EAAE,SAAS,WAAW,GAA8C;AAClG,QAAM,mBAAoC,CAAC;AAE3C,mBAAiB,gBAAgB,QAAQ,SAAS;AAC9C,UAAM,QAAQ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E,KAAK,MAAM;AACzC,iBAAS,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,MAC7C,CAAC;AAAA,IACF,SAAS,OAAO;AACf,eAAS,EAAE,MAAM,SAAS,SAAS,MAAe,CAAC;AAAA,IACpD;AAAA,EACD,GAAG,CAAC,CAAC;AAEL,SAAO;AACR;","names":["state"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ExpoSQLiteDatabase } from "./driver.cjs";
|
|
2
|
+
interface MigrationConfig {
|
|
3
|
+
journal: {
|
|
4
|
+
entries: {
|
|
5
|
+
idx: number;
|
|
6
|
+
when: number;
|
|
7
|
+
tag: string;
|
|
8
|
+
breakpoints: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
migrations: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function migrate<TSchema extends Record<string, unknown>>(db: ExpoSQLiteDatabase<TSchema>, config: MigrationConfig): Promise<void>;
|
|
14
|
+
interface State {
|
|
15
|
+
success: boolean;
|
|
16
|
+
error?: Error;
|
|
17
|
+
}
|
|
18
|
+
export declare const useMigrations: (db: ExpoSQLiteDatabase<any>, migrations: {
|
|
19
|
+
journal: {
|
|
20
|
+
entries: {
|
|
21
|
+
idx: number;
|
|
22
|
+
when: number;
|
|
23
|
+
tag: string;
|
|
24
|
+
breakpoints: boolean;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
migrations: Record<string, string>;
|
|
28
|
+
}) => State;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ExpoSQLiteDatabase } from "./driver.js";
|
|
2
|
+
interface MigrationConfig {
|
|
3
|
+
journal: {
|
|
4
|
+
entries: {
|
|
5
|
+
idx: number;
|
|
6
|
+
when: number;
|
|
7
|
+
tag: string;
|
|
8
|
+
breakpoints: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
migrations: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function migrate<TSchema extends Record<string, unknown>>(db: ExpoSQLiteDatabase<TSchema>, config: MigrationConfig): Promise<void>;
|
|
14
|
+
interface State {
|
|
15
|
+
success: boolean;
|
|
16
|
+
error?: Error;
|
|
17
|
+
}
|
|
18
|
+
export declare const useMigrations: (db: ExpoSQLiteDatabase<any>, migrations: {
|
|
19
|
+
journal: {
|
|
20
|
+
entries: {
|
|
21
|
+
idx: number;
|
|
22
|
+
when: number;
|
|
23
|
+
tag: string;
|
|
24
|
+
breakpoints: boolean;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
migrations: Record<string, string>;
|
|
28
|
+
}) => State;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useEffect, useReducer } from "react";
|
|
2
|
+
async function readMigrationFiles({ journal, migrations }) {
|
|
3
|
+
const migrationQueries = [];
|
|
4
|
+
for await (const journalEntry of journal.entries) {
|
|
5
|
+
const query = migrations[`m${journalEntry.idx.toString().padStart(4, "0")}`];
|
|
6
|
+
if (!query) {
|
|
7
|
+
throw new Error(`Missing migration: ${journalEntry.tag}`);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
11
|
+
return it;
|
|
12
|
+
});
|
|
13
|
+
migrationQueries.push({
|
|
14
|
+
sql: result,
|
|
15
|
+
bps: journalEntry.breakpoints,
|
|
16
|
+
folderMillis: journalEntry.when,
|
|
17
|
+
hash: ""
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return migrationQueries;
|
|
24
|
+
}
|
|
25
|
+
async function migrate(db, config) {
|
|
26
|
+
const migrations = await readMigrationFiles(config);
|
|
27
|
+
return db.dialect.migrate(migrations, db.session);
|
|
28
|
+
}
|
|
29
|
+
const useMigrations = (db, migrations) => {
|
|
30
|
+
const initialState = {
|
|
31
|
+
success: false,
|
|
32
|
+
error: void 0
|
|
33
|
+
};
|
|
34
|
+
const fetchReducer = (state2, action) => {
|
|
35
|
+
switch (action.type) {
|
|
36
|
+
case "migrating": {
|
|
37
|
+
return { ...initialState };
|
|
38
|
+
}
|
|
39
|
+
case "migrated": {
|
|
40
|
+
return { ...initialState, success: action.payload };
|
|
41
|
+
}
|
|
42
|
+
case "error": {
|
|
43
|
+
return { ...initialState, error: action.payload };
|
|
44
|
+
}
|
|
45
|
+
default: {
|
|
46
|
+
return state2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const [state, dispatch] = useReducer(fetchReducer, initialState);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
dispatch({ type: "migrating" });
|
|
53
|
+
try {
|
|
54
|
+
migrate(db, migrations).then(() => {
|
|
55
|
+
dispatch({ type: "migrated", payload: true });
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
dispatch({ type: "error", payload: error });
|
|
59
|
+
}
|
|
60
|
+
}, []);
|
|
61
|
+
return state;
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
migrate,
|
|
65
|
+
useMigrations
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from \"react\";\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n journal: {\n entries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n };\n migrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n const migrationQueries: MigrationMeta[] = [];\n\n for await (const journalEntry of journal.entries) {\n const query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n if (!query) {\n throw new Error(`Missing migration: ${journalEntry.tag}`);\n }\n\n try {\n const result = query.split('--> statement-breakpoint').map((it) => {\n return it;\n });\n\n migrationQueries.push({\n sql: result,\n bps: journalEntry.breakpoints,\n folderMillis: journalEntry.when,\n hash: '',\n });\n } catch {\n throw new Error(`Failed to parse migration: ${journalEntry.tag}`);\n }\n }\n\n return migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n db: ExpoSQLiteDatabase<TSchema>,\n config: MigrationConfig,\n) {\n const migrations = await readMigrationFiles(config);\n return db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error }\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t}\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState }\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload }\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state\n\t\t\t}\n\t\t}\n\t}\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })\n\t\ttry {\n\t\t\tmigrate(db, migrations as any).then(() => {\n\t\t\t\tdispatch({ type: 'migrated', payload: true })\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tdispatch({ type: 'error', payload: error as Error })\n\t\t}\n\t}, []);\n\n\treturn state;\n}"],"mappings":"AAAA,SAAS,WAAW,kBAA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