drizzle-orm 0.29.1 → 0.29.2-0fd9727

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.
Files changed (46) hide show
  1. package/README.md +22 -140
  2. package/aws-data-api/common/index.cjs +14 -1
  3. package/aws-data-api/common/index.cjs.map +1 -1
  4. package/aws-data-api/common/index.js +14 -1
  5. package/aws-data-api/common/index.js.map +1 -1
  6. package/expo-sqlite/driver.cjs +56 -0
  7. package/expo-sqlite/driver.cjs.map +1 -0
  8. package/expo-sqlite/driver.d.cts +5 -0
  9. package/expo-sqlite/driver.d.ts +5 -0
  10. package/expo-sqlite/driver.js +35 -0
  11. package/expo-sqlite/driver.js.map +1 -0
  12. package/expo-sqlite/index.cjs +25 -0
  13. package/expo-sqlite/index.cjs.map +1 -0
  14. package/expo-sqlite/index.d.cts +2 -0
  15. package/expo-sqlite/index.d.ts +2 -0
  16. package/expo-sqlite/index.js +3 -0
  17. package/expo-sqlite/index.js.map +1 -0
  18. package/expo-sqlite/migrator.cjs +92 -0
  19. package/expo-sqlite/migrator.cjs.map +1 -0
  20. package/expo-sqlite/migrator.d.cts +29 -0
  21. package/expo-sqlite/migrator.d.ts +29 -0
  22. package/expo-sqlite/migrator.js +67 -0
  23. package/expo-sqlite/migrator.js.map +1 -0
  24. package/expo-sqlite/session.cjs +134 -0
  25. package/expo-sqlite/session.cjs.map +1 -0
  26. package/expo-sqlite/session.d.cts +46 -0
  27. package/expo-sqlite/session.d.ts +46 -0
  28. package/expo-sqlite/session.js +111 -0
  29. package/expo-sqlite/session.js.map +1 -0
  30. package/package.json +55 -1
  31. package/pg-core/utils/array.cjs +2 -2
  32. package/pg-core/utils/array.cjs.map +1 -1
  33. package/pg-core/utils/array.js +2 -2
  34. package/pg-core/utils/array.js.map +1 -1
  35. package/sql/expressions/conditions.cjs +2 -2
  36. package/sql/expressions/conditions.cjs.map +1 -1
  37. package/sql/expressions/conditions.js +2 -2
  38. package/sql/expressions/conditions.js.map +1 -1
  39. package/utils.cjs +2 -0
  40. package/utils.cjs.map +1 -1
  41. package/utils.js +2 -0
  42. package/utils.js.map +1 -1
  43. package/version.cjs +1 -1
  44. package/version.d.cts +1 -1
  45. package/version.d.ts +1 -1
  46. package/version.js +1 -1
package/README.md CHANGED
@@ -1,156 +1,38 @@
1
1
  <div align="center">
2
- <h1>Drizzle ORM <a href=""><img alt="npm" src="https://img.shields.io/npm/v/drizzle-orm?label="></a></h1>
3
- <img alt="npm" src="https://img.shields.io/npm/dm/drizzle-orm">
4
- <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/drizzle-orm">
5
- <a href="https://discord.gg/yfjTbVXMW4" target="_blank"><img alt="Discord" src="https://img.shields.io/discord/1043890932593987624?label=Discord"></a>
6
- <img alt="License" src="https://img.shields.io/npm/l/drizzle-orm">
7
- <h6><i>If you know SQL, you know Drizzle ORM</i></h6>
8
- <hr />
2
+ <img src="./misc/readme/logo-github-sq-dark.svg#gh-dark-mode-only" />
3
+ <img src="./misc/readme/logo-github-sq-light.svg#gh-light-mode-only" />
9
4
  </div>
10
5
 
11
- Drizzle ORM is a TypeScript ORM for SQL databases designed with maximum type safety in mind. It comes with a [drizzle-kit](https://github.com/drizzle-team/drizzle-kit-mirror) CLI companion for automatic SQL migrations generation. Drizzle ORM is meant to be a library, not a framework. It stays as an opt-in solution all the time at any levels.
12
- The ORM's main philosophy is "If you know SQL, you know Drizzle ORM". We follow the SQL-like syntax whenever possible, are strongly typed ground up, and fail at compile time, not in runtime.
6
+ <br/>
7
+ <div align="center">
8
+ <h3>Headless ORM for NodeJS, TypeScript and JavaScript 🚀</h3>
9
+ <a href="https://orm.drizzle.team">Website</a> •
10
+ <a href="https://orm.drizzle.team/docs/overview">Documentation</a> •
11
+ <a href="https://x.com/drizzleorm">Twitter</a> •
12
+ <a href="https://driz.link/discord">Discord</a>
13
+ </div>
13
14
 
14
- Drizzle ORM is being battle-tested on production projects by multiple teams 🚀 Give it a try and let us know if you have any questions or feedback on [Discord](https://discord.gg/yfjTbVXMW4).
15
+ <br/>
16
+ <br/>
15
17
 
16
- ## Features
18
+ ### What's Drizzle?
19
+ Drizzle is a modern TypeScript ORM developers [wanna use in their next project](https://stateofdb.com/tools/drizzle).
20
+ It is [lightweight](https://bundlephobia.com/package/drizzle-orm) at only ~7.4kb minified+gzipped, it's tree shakeable with exactly 0 dependencies.
17
21
 
18
- - Full type safety
19
- - [Smart automated migrations generation](https://github.com/drizzle-team/drizzle-kit-mirror)
20
- - No ORM learning curve
21
- - SQL-like syntax for table definitions and queries
22
- - Best in class fully typed joins
23
- - Fully typed partial and non-partial selects of any complexity
24
- - Auto-inferring of TS types for DB models for selections and insertions separately
25
- - [Zod schema generation](/drizzle-zod/README.md)
26
- - Zero dependencies
22
+ Drizzle **supports every PostgreSQL, MySQL and SQLite databases**, including serverless ones like [Turso](https://orm.drizzle.team/docs/get-started-sqlite#turso), [Neon](https://orm.drizzle.team/docs/get-started-postgresql#neon), Xata, [PlanetScale](https://orm.drizzle.team/docs/get-started-mysql#planetscale), [Cloudflare D1](https://orm.drizzle.team/docs/get-started-sqlite#cloudflare-d1), FlyIO LiteFS, [Vercel Postgres](https://orm.drizzle.team/docs/get-started-postgresql#vercel-postgres), [Supabase](https://orm.drizzle.team/docs/get-started-postgresql#supabase) and [AWS Data API](https://orm.drizzle.team/docs/get-started-postgresql#aws-data-api). No bells and whistles, no rust binaries, no serverless adapters, everything just works out of the box.
27
23
 
28
- ## Documentation
24
+ Drizzle is **serverless-ready by design**, it works in every major JavaScript runtime like NodeJS, Bun, Deno, Cloudflare Workers, Supabase functions, any Edge runtime and even in Browsers. With Drizzle you can be [fast out of the box](https://orm.drizzle.team/benchmarks), save time and costs while never introducing any data proxies into your infrastructure.
29
25
 
30
- Check the full documentation on [the website](https://orm.drizzle.team)
26
+ While you can use Drizzle as a JavaScript library, it shines in the TypeScript. It lets you **declare SQL schema** and build both [**relational**](https://orm.drizzle.team/docs/rqb) and [**SQL-like queries**](https://orm.drizzle.team/docs/select), while keeping the balance between type-safety and extensibility for toolmakers to build on top.
31
27
 
32
- ## Supported databases
33
- | Database | Support | | |
34
- | :-------------- | :-----: | :------------------------------------------------ | :-------------------------------------------------------------------- |
35
- | PostgreSQL | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
36
- | MySQL | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
37
- | SQLite | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
38
- | Cloudflare D1 | ✅ | [Docs](https://driz.li/docs-d1) | [Website](https://developers.cloudflare.com/d1) |
39
- | libSQL | ✅ | [Docs](/examples/libsql/README.md) | [Website](https://libsql.org) |
40
- | Turso | ✅ | [Docs](https://driz.li/docs-turso) | [Website](https://turso.tech) |
41
- | PlanetScale | ✅ | [Docs](https://driz.li/docs-planetscale) | [Website](https://planetscale.com/) |
42
- | Neon | ✅ | [Docs](https://driz.li/docs-neon) | [Website](https://neon.tech/) |
43
- | Vercel Postgres | ✅ | [Docs](https://driz.li/docs-vercel-postgres) | [Website](https://vercel.com/docs/storage/vercel-postgres/quickstart) |
44
- | Supabase | ✅ | [Docs](https://driz.li/docs-supabase) | [Website](https://supabase.com) |
45
- | DynamoDB | ⏳ | | |
46
- | MS SQL | ⏳ | | |
47
- | CockroachDB | ⏳ | | |
28
+ Drizzle comes with a powerful [Drizzle Kit CLI](https://orm.drizzle.team/kit-docs/overview) tool for you to have hasstle-free migrations. It can generate SQL migration files for you or apply schema changes directly to the database.
48
29
 
49
- ## Our sponsors ❤️
30
+ ### Documentation
31
+ Check the full documentation on [the website](https://orm.drizzle.team)
50
32
 
33
+ ### Our sponsors ❤️
51
34
  <p align="center">
52
35
  <a href="https://drizzle.team" target="_blank">
53
36
  <img src='https://api.drizzle.team/github/sponsors/svg'/>
54
37
  </a>
55
38
  </p>
56
-
57
- ## Installation
58
-
59
- ```bash
60
- npm install drizzle-orm
61
- npm install -D drizzle-kit
62
- ```
63
-
64
- ## Feature showcase (PostgreSQL)
65
-
66
- > **Note**: don't forget to install `pg` and `@types/pg` packages for this example to work.
67
-
68
- ```typescript
69
- import { drizzle } from 'drizzle-orm/node-postgres';
70
- import { integer, pgTable, serial, text, timestamp, varchar } from 'drizzle-orm/pg-core';
71
- import { InferModel, eq, sql } from 'drizzle-orm';
72
- import { Pool } from 'pg';
73
-
74
- export const users = pgTable('users', {
75
- id: serial('id').primaryKey(),
76
- fullName: text('full_name').notNull(),
77
- phone: varchar('phone', { length: 20 }).notNull(),
78
- role: text('role', { enum: ['user', 'admin'] }).default('user').notNull(),
79
- cityId: integer('city_id').references(() => cities.id),
80
- createdAt: timestamp('created_at').defaultNow().notNull(),
81
- updatedAt: timestamp('updated_at').defaultNow().notNull(),
82
- });
83
-
84
- export type User = InferModel<typeof users>;
85
- export type NewUser = InferModel<typeof users, 'insert'>;
86
-
87
- export const cities = pgTable('cities', {
88
- id: serial('id').primaryKey(),
89
- name: text('name').notNull(),
90
- });
91
-
92
- export type City = InferModel<typeof cities>;
93
- export type NewCity = InferModel<typeof cities, 'insert'>;
94
-
95
- const pool = new Pool({
96
- connectionString: 'postgres://user:password@host:port/db',
97
- });
98
-
99
- const db = drizzle(pool);
100
-
101
- // Insert
102
- const newUser: NewUser = {
103
- fullName: 'John Doe',
104
- phone: '+123456789',
105
- };
106
- const insertedUsers /* : User[] */ = await db.insert(users).values(newUser).returning();
107
- const insertedUser = insertedUsers[0]!;
108
-
109
- const newCity: NewCity = {
110
- name: 'New York',
111
- };
112
- const insertedCities /* : City[] */ = await db.insert(cities).values(newCity).returning();
113
- const insertedCity = insertedCities[0]!;
114
-
115
- // Update
116
- const updateResult /* : { updated: Date }[] */ = await db.update(users)
117
- .set({ cityId: insertedCity.id, updatedAt: new Date() })
118
- .where(eq(users.id, insertedUser.id))
119
- .returning({ updated: users.updatedAt });
120
-
121
- // Select
122
- const allUsers /* : User[] */ = await db.select().from(users);
123
-
124
- // Select custom fields
125
- const upperCaseNames /* : { id: number; name: string }[] */ = await db
126
- .select({
127
- id: users.id,
128
- name: sql<string>`upper(${users.fullName})`,
129
- })
130
- .from(users);
131
-
132
- // Joins
133
- // You wouldn't BELIEVE how SMART the result type is! 😱
134
- const allUsersWithCities = await db
135
- .select({
136
- id: users.id,
137
- name: users.fullName,
138
- city: {
139
- id: cities.id,
140
- name: cities.name,
141
- },
142
- })
143
- .from(users)
144
- .leftJoin(cities, eq(users.cityId, cities.id));
145
-
146
- // Delete
147
- const deletedNames /* : { name: string }[] */ = await db.delete(users)
148
- .where(eq(users.id, insertedUser.id))
149
- .returning({ name: users.fullName });
150
- ```
151
-
152
- **See full docs for further reference:**
153
-
154
- - [PostgreSQL](./drizzle-orm/src/pg-core/README.md)
155
- - [MySQL](./drizzle-orm/src/mysql-core/README.md)
156
- - [SQLite](./drizzle-orm/src/sqlite-core/README.md)
@@ -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
- response.value = response.typeHint === "DATE" ? { stringValue: value.split("T")[0] } : { stringValue: value };
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\tresponse.value = response.typeHint === 'DATE'\n\t\t\t? { stringValue: value.split('T')[0]! }\n\t\t\t: { stringValue: value };\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\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,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,gCAAS;AAAA,EACjB,WAAW,YAAY,WAAW;AACjC,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,aAAa;AACnC,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,gCAAS;AAAA,EACjB,OAAO;AACN,WAAO;AAAA,EACR;AACD;AAEO,SAAS,aAAa,OAAY,SAAoE;AAC5G,QAAM,WAAkD;AAAA,IACvD,OAAO,CAAC;AAAA,IACR,UAAU,qBAAqB,OAAO;AAAA,EACvC;AAEA,MAAI,UAAU,MAAM;AACnB,aAAS,QAAQ,EAAE,QAAQ,KAAK;AAAA,EACjC,WAAW,OAAO,UAAU,UAAU;AACrC,aAAS,QAAQ,SAAS,aAAa,SACpC,EAAE,aAAa,MAAM,MAAM,GAAG,EAAE,CAAC,EAAG,IACpC,EAAE,aAAa,MAAM;AAAA,EACzB,WAAW,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,GAAG;AAChE,aAAS,QAAQ,EAAE,WAAW,MAAM;AAAA,EACrC,WAAW,OAAO,UAAU,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;AACjC,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":[]}
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,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,gCAAS;AAAA,EACjB,WAAW,YAAY,WAAW;AACjC,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,aAAa;AACnC,WAAO,gCAAS;AAAA,EACjB,WAAW,YAAY,QAAQ;AAC9B,WAAO,gCAAS;AAAA,EACjB,OAAO;AACN,WAAO;AAAA,EACR;AACD;AAEO,SAAS,aAAa,OAAY,SAAoE;AAC5G,QAAM,WAAkD;AAAA,IACvD,OAAO,CAAC;AAAA,IACR,UAAU,qBAAqB,OAAO;AAAA,EACvC;AAEA,MAAI,UAAU,MAAM;AACnB,aAAS,QAAQ,EAAE,QAAQ,KAAK;AAAA,EACjC,WAAW,OAAO,UAAU,UAAU;AACrC,YAAQ,SAAS,UAAU;AAAA,MAC1B,KAAK,gCAAS,MAAM;AACnB,iBAAS,QAAQ,EAAE,aAAa,MAAM,MAAM,GAAG,EAAE,CAAC,EAAG;AACrD;AAAA,MACD;AAAA,MACA,KAAK,gCAAS,WAAW;AACxB,iBAAS,QAAQ,EAAE,aAAa,MAAM,QAAQ,KAAK,GAAG,EAAE,QAAQ,KAAK,EAAE,EAAE;AACzE;AAAA,MACD;AAAA,MACA,SAAS;AACR,iBAAS,QAAQ,EAAE,aAAa,MAAM;AACtC;AAAA,MACD;AAAA,IACD;AAAA,EACD,WAAW,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,GAAG;AAChE,aAAS,QAAQ,EAAE,WAAW,MAAM;AAAA,EACrC,WAAW,OAAO,UAAU,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
- response.value = response.typeHint === "DATE" ? { stringValue: value.split("T")[0] } : { stringValue: value };
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\tresponse.value = response.typeHint === 'DATE'\n\t\t\t? { stringValue: value.split('T')[0]! }\n\t\t\t: { stringValue: value };\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\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,qBAAq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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,E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AAG,EAAE,QAAQ,KAAK,EAAE,EAAE;AAAA,EACxF,OAAO;AACN,UAAM,IAAI,MAAM,oBAAoB,KAAK,EAAE;AAAA,EAC5C;AAEA,SAAO;AACR;","names":[]}
@@ -0,0 +1,56 @@
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 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,2 @@
1
+ export * from "./driver.cjs";
2
+ export * from "./session.cjs";
@@ -0,0 +1,2 @@
1
+ export * from "./driver.js";
2
+ export * from "./session.js";
@@ -0,0 +1,3 @@
1
+ export * from "./driver.js";
2
+ export * from "./session.js";
3
+ //# sourceMappingURL=index.js.map
@@ -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,WAAW,IAAI,aAAa,IAA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AAS,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 {};