@xata.io/drizzle 0.0.0-alpha.v0e4f4d5
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/.turbo/turbo-build.log +14 -0
- package/CHANGELOG.md +17 -0
- package/LICENSE +201 -0
- package/README.md +73 -0
- package/dist/index.cjs +216 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.mjs +211 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
> @xata.io/drizzle@0.0.1 build /home/runner/work/client-ts/client-ts/packages/plugin-client-drizzle
|
|
3
|
+
> rimraf dist && rollup -c
|
|
4
|
+
|
|
5
|
+
[36m
|
|
6
|
+
[1msrc/index.ts[22m → [1mdist/index.cjs, dist/index.mjs[22m...[39m
|
|
7
|
+
[1m[33m(!) Unresolved dependencies[39m[22m
|
|
8
|
+
[90mhttps://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency[39m
|
|
9
|
+
[1mdrizzle-orm[22m (imported by "src/driver.ts", "src/session.ts" and "src/utils.ts")
|
|
10
|
+
[1mdrizzle-orm/pg-core[22m (imported by "src/driver.ts", "src/session.ts" and "src/generate.ts")
|
|
11
|
+
[32mcreated [1mdist/index.cjs, dist/index.mjs[22m in [1m639ms[22m[39m
|
|
12
|
+
[36m
|
|
13
|
+
[1msrc/index.ts[22m → [1mdist/index.d.ts[22m...[39m
|
|
14
|
+
[32mcreated [1mdist/index.d.ts[22m in [1m11s[22m[39m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @xata.io/drizzle
|
|
2
|
+
|
|
3
|
+
## 0.0.0-alpha.v0e4f4d5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @xata.io/client@0.0.0-alpha.v0e4f4d5
|
|
9
|
+
|
|
10
|
+
## 0.0.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#1145](https://github.com/xataio/client-ts/pull/1145) [`e41d7faf`](https://github.com/xataio/client-ts/commit/e41d7faf40747fd31a08cdcd767d9596f88e4a20) Thanks [@SferaDev](https://github.com/SferaDev)! - Initial release
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`22fccb51`](https://github.com/xataio/client-ts/commit/22fccb51709749c319897702c15749b74ce4b820)]:
|
|
17
|
+
- @xata.io/client@0.26.2
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @xata.io/drizzle
|
|
2
|
+
|
|
3
|
+
A [Drizzle](https://github.com/drizzle-team/drizzle-orm) driver for [Xata](https://xata.io), using the [Xata serverless driver for TypeScript](https://github.com/xataio/client-ts).
|
|
4
|
+
|
|
5
|
+
The goal of this package is polish the implementation and contribute it back to the official Drizzle repository.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You should install both `drizzle-orm` and `@xata.io/drizzle` with `@xata.io/client`. You can install them with your favorite package manager:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# with pnpm
|
|
13
|
+
pnpm add drizzle-orm @xata.io/drizzle @xata.io/client
|
|
14
|
+
|
|
15
|
+
# with yarn
|
|
16
|
+
yarn add drizzle-orm @xata.io/drizzle @xata.io/client
|
|
17
|
+
|
|
18
|
+
# with npm
|
|
19
|
+
npm install drizzle-orm @xata.io/drizzle @xata.io/client
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
To work with drizzle you need to define your models and then create a drizzle instance with the models.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { drizzle } from '@xata.io/drizzle';
|
|
28
|
+
import { sql } from 'drizzle-orm';
|
|
29
|
+
import { pgTable, text } from 'drizzle-orm/pg-core';
|
|
30
|
+
import { getXataClient } from './xata';
|
|
31
|
+
|
|
32
|
+
const xata = getXataClient();
|
|
33
|
+
|
|
34
|
+
const drivers = pgTable('drivers', {
|
|
35
|
+
id: text('id').primaryKey(),
|
|
36
|
+
surname: text('surname'),
|
|
37
|
+
forename: text('forename'),
|
|
38
|
+
nationality: text('nationality')
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const schema = {
|
|
42
|
+
drivers
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const db = drizzle(xata, { schema });
|
|
46
|
+
|
|
47
|
+
const result = await db.execute(sql`select * from ${drivers} where ${drivers.nationality} = 'Spanish'`);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## [Experimental] Model generation
|
|
51
|
+
|
|
52
|
+
We offer an experimental model generation helper that will generate the models for you from your `tables` array in your `xata.ts` file. Since it's a work in progress, we don't recommend using it in your applications yet, please build your models manually. However, we would love to hear your feedback on it.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { drizzle, buildModels } from '@xata.io/drizzle';
|
|
56
|
+
import { sql } from 'drizzle-orm';
|
|
57
|
+
import { pgTable, text } from 'drizzle-orm/pg-core';
|
|
58
|
+
import { getXataClient, tables } from './xata';
|
|
59
|
+
|
|
60
|
+
const xata = getXataClient();
|
|
61
|
+
|
|
62
|
+
const schema = buildModels(tables);
|
|
63
|
+
const { drivers } = schema;
|
|
64
|
+
|
|
65
|
+
const db = drizzle(xata, { schema });
|
|
66
|
+
|
|
67
|
+
const result = await db.execute(sql`select * from ${drivers} where ${drivers.nationality} = 'Spanish'`);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Limitations
|
|
71
|
+
|
|
72
|
+
- Migrations from drizzle are not supported yet, we will add them once the SQL endpoint allows it.
|
|
73
|
+
- Transactions are not supported yet, we will add them once the SQL endpoint allows it.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var drizzleOrm = require('drizzle-orm');
|
|
4
|
+
var pgCore = require('drizzle-orm/pg-core');
|
|
5
|
+
|
|
6
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
7
|
+
const nullifyMap = {};
|
|
8
|
+
const result = columns.reduce((result2, { path, field }, columnIndex) => {
|
|
9
|
+
let decoder;
|
|
10
|
+
if (drizzleOrm.is(field, drizzleOrm.Column)) {
|
|
11
|
+
decoder = field;
|
|
12
|
+
} else if (drizzleOrm.is(field, drizzleOrm.SQL)) {
|
|
13
|
+
decoder = field.decoder;
|
|
14
|
+
} else {
|
|
15
|
+
decoder = field.sql.decoder;
|
|
16
|
+
}
|
|
17
|
+
let node = result2;
|
|
18
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
19
|
+
if (pathChunkIndex < path.length - 1) {
|
|
20
|
+
if (!(pathChunk in node)) {
|
|
21
|
+
node[pathChunk] = {};
|
|
22
|
+
}
|
|
23
|
+
node = node[pathChunk];
|
|
24
|
+
} else {
|
|
25
|
+
const rawValue = row[columnIndex];
|
|
26
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
27
|
+
if (joinsNotNullableMap && drizzleOrm.is(field, drizzleOrm.Column) && path.length === 2) {
|
|
28
|
+
const objectName = path[0];
|
|
29
|
+
if (!(objectName in nullifyMap)) {
|
|
30
|
+
nullifyMap[objectName] = value === null ? drizzleOrm.getTableName(field.table) : false;
|
|
31
|
+
} else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== drizzleOrm.getTableName(field.table)) {
|
|
32
|
+
nullifyMap[objectName] = false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result2;
|
|
38
|
+
}, {});
|
|
39
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
40
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
41
|
+
if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) {
|
|
42
|
+
result[objectName] = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
const exhaustiveCheck = (x) => {
|
|
49
|
+
throw new Error(`Unhandled discriminated union member: ${x}`);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var __defProp = Object.defineProperty;
|
|
53
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
54
|
+
var __publicField = (obj, key, value) => {
|
|
55
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
58
|
+
var _a, _b;
|
|
59
|
+
class XataPreparedQuery extends pgCore.PreparedQuery {
|
|
60
|
+
constructor(client, queryString, params, logger, fields, name, customResultMapper) {
|
|
61
|
+
super();
|
|
62
|
+
this.client = client;
|
|
63
|
+
this.params = params;
|
|
64
|
+
this.logger = logger;
|
|
65
|
+
this.fields = fields;
|
|
66
|
+
this.customResultMapper = customResultMapper;
|
|
67
|
+
__publicField(this, "query");
|
|
68
|
+
this.query = {
|
|
69
|
+
name,
|
|
70
|
+
statement: queryString
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async execute(placeholderValues = {}) {
|
|
74
|
+
const params = drizzleOrm.fillPlaceholders(this.params, placeholderValues);
|
|
75
|
+
this.logger.logQuery(this.query.statement, params);
|
|
76
|
+
const { records } = await this.client.sql({
|
|
77
|
+
statement: this.query.statement,
|
|
78
|
+
params
|
|
79
|
+
});
|
|
80
|
+
const fields = this.fields ?? Object.keys(records[0]).map(
|
|
81
|
+
(key) => ({
|
|
82
|
+
path: [key],
|
|
83
|
+
field: {
|
|
84
|
+
sql: {
|
|
85
|
+
decoder: {
|
|
86
|
+
mapFromDriverValue: (value) => value
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
const rows = records.map((record) => fields.map((field) => record[field.path.join(".")]));
|
|
93
|
+
if (this.customResultMapper) {
|
|
94
|
+
return this.customResultMapper(rows);
|
|
95
|
+
}
|
|
96
|
+
return rows.map((row) => mapResultRow(fields, row, void 0));
|
|
97
|
+
}
|
|
98
|
+
async all(placeholderValues = {}) {
|
|
99
|
+
const params = drizzleOrm.fillPlaceholders(this.params, placeholderValues);
|
|
100
|
+
this.logger.logQuery(this.query.statement, params);
|
|
101
|
+
const { records } = await this.client.sql({
|
|
102
|
+
statement: this.query.statement,
|
|
103
|
+
params
|
|
104
|
+
});
|
|
105
|
+
return records;
|
|
106
|
+
}
|
|
107
|
+
async values(placeholderValues = {}) {
|
|
108
|
+
const params = drizzleOrm.fillPlaceholders(this.params, placeholderValues);
|
|
109
|
+
this.logger.logQuery(this.query.statement, params);
|
|
110
|
+
const { records } = await this.client.sql({
|
|
111
|
+
statement: this.query.statement,
|
|
112
|
+
params
|
|
113
|
+
});
|
|
114
|
+
return records;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_a = drizzleOrm.entityKind;
|
|
118
|
+
__publicField(XataPreparedQuery, _a, "VercelPgPreparedQuery");
|
|
119
|
+
class XataSession extends pgCore.PgSession {
|
|
120
|
+
constructor(client, dialect, schema, options = {}) {
|
|
121
|
+
super(dialect);
|
|
122
|
+
this.client = client;
|
|
123
|
+
this.schema = schema;
|
|
124
|
+
this.options = options;
|
|
125
|
+
__publicField(this, "logger");
|
|
126
|
+
this.logger = options.logger ?? new drizzleOrm.NoopLogger();
|
|
127
|
+
}
|
|
128
|
+
prepareQuery(query, fields, name, customResultMapper) {
|
|
129
|
+
return new XataPreparedQuery(this.client, query.sql, query.params, this.logger, fields, name, customResultMapper);
|
|
130
|
+
}
|
|
131
|
+
async query(query, params) {
|
|
132
|
+
this.logger.logQuery(query, params);
|
|
133
|
+
return await this.client.sql({ statement: query, params });
|
|
134
|
+
}
|
|
135
|
+
async queryObjects(query, params) {
|
|
136
|
+
return this.client.sql({ statement: query, params });
|
|
137
|
+
}
|
|
138
|
+
async transaction(_transaction, _config) {
|
|
139
|
+
throw new Error("Transactions are not supported");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
_b = drizzleOrm.entityKind;
|
|
143
|
+
__publicField(XataSession, _b, "VercelPgSession");
|
|
144
|
+
|
|
145
|
+
function drizzle(client, config = {}) {
|
|
146
|
+
const dialect = new pgCore.PgDialect();
|
|
147
|
+
let logger;
|
|
148
|
+
if (config.logger === true) {
|
|
149
|
+
logger = new drizzleOrm.DefaultLogger();
|
|
150
|
+
} else if (config.logger !== false) {
|
|
151
|
+
logger = config.logger;
|
|
152
|
+
}
|
|
153
|
+
let schema;
|
|
154
|
+
if (config.schema) {
|
|
155
|
+
const tablesConfig = drizzleOrm.extractTablesRelationalConfig(config.schema, drizzleOrm.createTableRelationsHelpers);
|
|
156
|
+
schema = {
|
|
157
|
+
fullSchema: config.schema,
|
|
158
|
+
schema: tablesConfig.tables,
|
|
159
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const session = new XataSession(client, dialect, schema, { logger });
|
|
163
|
+
return new pgCore.PgDatabase(dialect, session, schema);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function buildColumnType(column) {
|
|
167
|
+
switch (column.type) {
|
|
168
|
+
case "string":
|
|
169
|
+
case "text":
|
|
170
|
+
case "email":
|
|
171
|
+
case "link":
|
|
172
|
+
return pgCore.text(column.name);
|
|
173
|
+
case "bool":
|
|
174
|
+
return pgCore.boolean(column.name);
|
|
175
|
+
case "int":
|
|
176
|
+
return pgCore.integer(column.name);
|
|
177
|
+
case "float":
|
|
178
|
+
return pgCore.decimal(column.name);
|
|
179
|
+
case "datetime":
|
|
180
|
+
return pgCore.date(column.name);
|
|
181
|
+
case "multiple":
|
|
182
|
+
case "object":
|
|
183
|
+
case "vector":
|
|
184
|
+
case "file[]":
|
|
185
|
+
case "file":
|
|
186
|
+
case "json":
|
|
187
|
+
throw new Error(`Unsupported column type: ${column.type}`);
|
|
188
|
+
default:
|
|
189
|
+
return exhaustiveCheck(column.type);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function buildColumn(column) {
|
|
193
|
+
let type = buildColumnType(column);
|
|
194
|
+
if (column.notNull) {
|
|
195
|
+
type = type.notNull();
|
|
196
|
+
}
|
|
197
|
+
if (column.unique) {
|
|
198
|
+
type = type.unique();
|
|
199
|
+
}
|
|
200
|
+
return type;
|
|
201
|
+
}
|
|
202
|
+
function buildTable(schema) {
|
|
203
|
+
const columns = schema.columns.map((column) => [column.name, buildColumn(column)]);
|
|
204
|
+
const definition = { id: pgCore.text("id"), ...Object.fromEntries(columns) };
|
|
205
|
+
return pgCore.pgTable(schema.name, definition);
|
|
206
|
+
}
|
|
207
|
+
function buildModels(tables) {
|
|
208
|
+
const entries = tables.map((table) => [table.name, buildTable(table)]);
|
|
209
|
+
return Object.fromEntries(entries);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
exports.XataPreparedQuery = XataPreparedQuery;
|
|
213
|
+
exports.XataSession = XataSession;
|
|
214
|
+
exports.buildModels = buildModels;
|
|
215
|
+
exports.drizzle = drizzle;
|
|
216
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/session.ts","../src/driver.ts","../src/generate.ts"],"sourcesContent":["import { AnyColumn, Column, DriverValueDecoder, SQL, getTableName, is } from 'drizzle-orm';\n\ntype SelectedFieldsOrdered<TColumn extends Column> = {\n path: string[];\n field: TColumn | SQL | SQL.Aliased;\n}[];\n\nexport function mapResultRow<TResult>(\n columns: SelectedFieldsOrdered<AnyColumn>,\n row: unknown[],\n joinsNotNullableMap: Record<string, boolean> | undefined\n): TResult {\n // Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise\n const nullifyMap: Record<string, string | false> = {};\n\n const result = columns.reduce<Record<string, any>>((result, { path, field }, columnIndex) => {\n let decoder: DriverValueDecoder<unknown, unknown>;\n if (is(field, Column)) {\n decoder = field;\n } else if (is(field, SQL)) {\n decoder = (field as any).decoder;\n } else {\n decoder = (field as any).sql.decoder;\n }\n let node = result;\n for (const [pathChunkIndex, pathChunk] of path.entries()) {\n if (pathChunkIndex < path.length - 1) {\n if (!(pathChunk in node)) {\n node[pathChunk] = {};\n }\n node = node[pathChunk];\n } else {\n const rawValue = row[columnIndex]!;\n const value = (node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue));\n\n if (joinsNotNullableMap && is(field, Column) && path.length === 2) {\n const objectName = path[0]!;\n if (!(objectName in nullifyMap)) {\n nullifyMap[objectName] = value === null ? getTableName(field.table) : false;\n } else if (\n typeof nullifyMap[objectName] === 'string' &&\n nullifyMap[objectName] !== getTableName(field.table)\n ) {\n nullifyMap[objectName] = false;\n }\n }\n }\n }\n return result;\n }, {});\n\n // Nullify all nested objects from nullifyMap that are nullable\n if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {\n for (const [objectName, tableName] of Object.entries(nullifyMap)) {\n if (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {\n result[objectName] = null;\n }\n }\n }\n\n return result as TResult;\n}\n\nexport const exhaustiveCheck = (x: never): never => {\n throw new Error(`Unhandled discriminated union member: ${x}`);\n};\n","import {\n Assume,\n Logger,\n NoopLogger,\n Query,\n RelationalSchemaConfig,\n TablesRelationalConfig,\n entityKind,\n fillPlaceholders\n} from 'drizzle-orm';\nimport {\n PgDialect,\n PgSession,\n PgTransactionConfig,\n PreparedQuery,\n PreparedQueryConfig,\n QueryResultHKT,\n SelectedFieldsOrdered\n} from 'drizzle-orm/pg-core';\nimport { XataClient } from './driver';\nimport { mapResultRow } from './utils';\n\ntype QueryResult<T = Record<string, unknown>> = {\n records: T[];\n warning?: string;\n};\n\nexport class XataPreparedQuery<T extends PreparedQueryConfig> extends PreparedQuery<T> {\n static readonly [entityKind]: string = 'VercelPgPreparedQuery';\n\n private query: {\n name: string | undefined;\n statement: string;\n };\n\n constructor(\n private client: XataClient,\n queryString: string,\n private params: unknown[],\n private logger: Logger,\n private fields: SelectedFieldsOrdered | undefined,\n name: string | undefined,\n private customResultMapper?: (rows: unknown[][]) => T['execute']\n ) {\n super();\n\n this.query = {\n name,\n statement: queryString\n };\n }\n\n async execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n const params = fillPlaceholders(this.params, placeholderValues);\n\n this.logger.logQuery(this.query.statement, params);\n\n const { records } = await this.client.sql<Record<string, unknown>>({\n statement: this.query.statement,\n params\n });\n\n // FIXME: This is a hack, we should be able to get the fields from the query but SELECT * fails\n const fields =\n this.fields ??\n Object.keys(records[0]!).map(\n (key) =>\n ({\n path: [key],\n field: {\n sql: {\n decoder: {\n mapFromDriverValue: (value: unknown) => value\n }\n }\n }\n } as any)\n );\n\n const rows = records.map((record) => fields.map((field) => record[field.path.join('.')]));\n\n if (this.customResultMapper) {\n return this.customResultMapper(rows);\n }\n\n return rows.map((row) => mapResultRow<T['execute']>(fields, row, undefined));\n }\n\n async all(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n const params = fillPlaceholders(this.params, placeholderValues);\n this.logger.logQuery(this.query.statement, params);\n\n const { records } = await this.client.sql({\n statement: this.query.statement,\n params\n });\n\n return records;\n }\n\n async values(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['values']> {\n const params = fillPlaceholders(this.params, placeholderValues);\n this.logger.logQuery(this.query.statement, params);\n\n const { records } = await this.client.sql({\n statement: this.query.statement,\n params\n });\n\n return records;\n }\n}\n\nexport interface XataSessionOptions {\n logger?: Logger;\n}\n\nexport class XataSession<\n TFullSchema extends Record<string, unknown>,\n TSchema extends TablesRelationalConfig\n> extends PgSession<XataQueryResultHKT, TFullSchema, TSchema> {\n static readonly [entityKind]: string = 'VercelPgSession';\n\n private logger: Logger;\n\n constructor(\n private client: XataClient,\n dialect: PgDialect,\n private schema: RelationalSchemaConfig<TSchema> | undefined,\n private options: XataSessionOptions = {}\n ) {\n super(dialect);\n this.logger = options.logger ?? new NoopLogger();\n }\n\n prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n query: Query,\n fields: SelectedFieldsOrdered | undefined,\n name: string | undefined,\n customResultMapper?: (rows: unknown[][]) => T['execute']\n ): PreparedQuery<T> {\n return new XataPreparedQuery(this.client, query.sql, query.params, this.logger, fields, name, customResultMapper);\n }\n\n async query(query: string, params: unknown[]): Promise<QueryResult> {\n this.logger.logQuery(query, params);\n return await this.client.sql({ statement: query, params });\n }\n\n async queryObjects<T extends Record<string, unknown>>(query: string, params: unknown[]): Promise<QueryResult<T>> {\n return this.client.sql({ statement: query, params });\n }\n\n override async transaction<T>(\n _transaction: (tx: any) => Promise<T>,\n _config?: PgTransactionConfig | undefined\n ): Promise<T> {\n throw new Error('Transactions are not supported');\n }\n}\n\nexport interface XataQueryResultHKT extends QueryResultHKT {\n type: QueryResult<Assume<this['row'], Record<string, unknown>>[]>;\n}\n","import { SQLPluginResult } from '@xata.io/client';\nimport {\n DefaultLogger,\n DrizzleConfig,\n RelationalSchemaConfig,\n TablesRelationalConfig,\n createTableRelationsHelpers,\n extractTablesRelationalConfig\n} from 'drizzle-orm';\nimport { PgDatabase, PgDialect } from 'drizzle-orm/pg-core';\nimport { XataQueryResultHKT, XataSession } from './session';\n\nexport type XataDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = PgDatabase<\n XataQueryResultHKT,\n TSchema\n>;\n\nexport type XataClient = {\n sql: SQLPluginResult;\n};\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n client: XataClient,\n config: DrizzleConfig<TSchema> = {}\n): XataDatabase<TSchema> {\n const dialect = new PgDialect();\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(config.schema, createTableRelationsHelpers);\n schema = {\n fullSchema: config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap\n };\n }\n\n const session = new XataSession(client, dialect, schema, { logger });\n return new PgDatabase(dialect, session, schema) as XataDatabase<TSchema>;\n}\n","import { BaseSchema, Schemas } from '@xata.io/client';\nimport { boolean, date, decimal, integer, pgTable, text } from 'drizzle-orm/pg-core';\nimport { exhaustiveCheck } from './utils';\n\nfunction buildColumnType(column: Schemas.Column) {\n switch (column.type) {\n case 'string':\n case 'text':\n case 'email':\n case 'link':\n return text(column.name);\n case 'bool':\n return boolean(column.name);\n case 'int':\n return integer(column.name);\n case 'float':\n return decimal(column.name);\n case 'datetime':\n return date(column.name);\n case 'multiple':\n case 'object':\n case 'vector':\n case 'file[]':\n case 'file':\n case 'json':\n throw new Error(`Unsupported column type: ${column.type}`);\n default:\n return exhaustiveCheck(column.type);\n }\n}\n\nfunction buildColumn(column: Schemas.Column) {\n let type = buildColumnType(column);\n\n if (column.notNull) {\n type = type.notNull();\n }\n\n if (column.unique) {\n type = type.unique();\n }\n\n return type;\n}\n\nfunction buildTable(schema: Schemas.Table) {\n const columns = schema.columns.map((column) => [column.name, buildColumn(column)]);\n const definition = { id: text('id'), ...Object.fromEntries(columns) };\n return pgTable(schema.name, definition);\n}\n\nexport type DrizzleModels<T extends readonly BaseSchema[]> = T extends never[]\n ? Record<string, Record<string, any>>\n : T extends readonly unknown[]\n ? T[number] extends { name: string; columns: readonly unknown[] }\n ? {\n [K in T[number]['name']]: ReturnType<typeof buildTable>;\n }\n : never\n : never;\n\nexport function buildModels<T extends readonly BaseSchema[]>(tables: T): DrizzleModels<T> {\n const entries = tables.map((table) => [table.name, buildTable(table as Schemas.Table)]);\n return Object.fromEntries(entries);\n}\n"],"names":["result","is","Column","SQL","getTableName","PreparedQuery","fillPlaceholders","entityKind","PgSession","NoopLogger","PgDialect","DefaultLogger","extractTablesRelationalConfig","createTableRelationsHelpers","PgDatabase","text","boolean","integer","decimal","date","pgTable"],"mappings":";;;;;AAOgB,SAAA,YAAA,CACd,OACA,EAAA,GAAA,EACA,mBACS,EAAA;AAET,EAAA,MAAM,aAA6C,EAAC,CAAA;AAEpD,EAAM,MAAA,MAAA,GAAS,QAAQ,MAA4B,CAAA,CAACA,SAAQ,EAAE,IAAA,EAAM,KAAM,EAAA,EAAG,WAAgB,KAAA;AAC3F,IAAI,IAAA,OAAA,CAAA;AACJ,IAAI,IAAAC,aAAA,CAAG,KAAO,EAAAC,iBAAM,CAAG,EAAA;AACrB,MAAU,OAAA,GAAA,KAAA,CAAA;AAAA,KACD,MAAA,IAAAD,aAAA,CAAG,KAAO,EAAAE,cAAG,CAAG,EAAA;AACzB,MAAA,OAAA,GAAW,KAAc,CAAA,OAAA,CAAA;AAAA,KACpB,MAAA;AACL,MAAA,OAAA,GAAW,MAAc,GAAI,CAAA,OAAA,CAAA;AAAA,KAC/B;AACA,IAAA,IAAI,IAAOH,GAAAA,OAAAA,CAAAA;AACX,IAAA,KAAA,MAAW,CAAC,cAAgB,EAAA,SAAS,CAAK,IAAA,IAAA,CAAK,SAAW,EAAA;AACxD,MAAI,IAAA,cAAA,GAAiB,IAAK,CAAA,MAAA,GAAS,CAAG,EAAA;AACpC,QAAI,IAAA,EAAE,aAAa,IAAO,CAAA,EAAA;AACxB,UAAK,IAAA,CAAA,SAAS,IAAI,EAAC,CAAA;AAAA,SACrB;AACA,QAAA,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,YAAY,MAAwB,EAAA;AAC3C,EAAI,IAAA,IAAA,GAAO,gBAAgB,MAAM,CAAA,CAAA;AAEjC,EAAA,IAAI,OAAO,OAAS,EAAA;AAClB,IAAA,IAAA,GAAO,KAAK,OAAQ,EAAA,CAAA;AAAA,GACtB;AAEA,EAAA,IAAI,OAAO,MAAQ,EAAA;AACjB,IAAA,IAAA,GAAO,KAAK,MAAO,EAAA,CAAA;AAAA,GACrB;AAEA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAEA,SAAS,WAAW,MAAuB,EAAA;AACzC,EAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,GAAA,CAAI,CAAC,MAAA,KAAW,CAAC,MAAA,CAAO,IAAM,EAAA,WAAA,CAAY,MAAM,CAAC,CAAC,CAAA,CAAA;AACjF,EAAM,MAAA,UAAA,GAAa,EAAE,EAAA,EAAIJ,WAAK,CAAA,IAAI,GAAG,GAAG,MAAA,CAAO,WAAY,CAAA,OAAO,CAAE,EAAA,CAAA;AACpE,EAAO,OAAAK,cAAA,CAAQ,MAAO,CAAA,IAAA,EAAM,UAAU,CAAA,CAAA;AACxC,CAAA;AAYO,SAAS,YAA6C,MAA6B,EAAA;AACxF,EAAM,MAAA,OAAA,GAAU,MAAO,CAAA,GAAA,CAAI,CAAC,KAAA,KAAU,CAAC,KAAA,CAAM,IAAM,EAAA,UAAA,CAAW,KAAsB,CAAC,CAAC,CAAA,CAAA;AACtF,EAAO,OAAA,MAAA,CAAO,YAAY,OAAO,CAAA,CAAA;AACnC;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SQLPluginResult, BaseSchema, Schemas } from '@xata.io/client';
|
|
2
|
+
import * as drizzle_orm from 'drizzle-orm';
|
|
3
|
+
import { entityKind, Logger, TablesRelationalConfig, RelationalSchemaConfig, Query, Assume, DrizzleConfig } from 'drizzle-orm';
|
|
4
|
+
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
5
|
+
import { PreparedQueryConfig, PreparedQuery, SelectedFieldsOrdered, PgSession, PgDialect, PgTransactionConfig, QueryResultHKT, PgDatabase } from 'drizzle-orm/pg-core';
|
|
6
|
+
|
|
7
|
+
type QueryResult<T = Record<string, unknown>> = {
|
|
8
|
+
records: T[];
|
|
9
|
+
warning?: string;
|
|
10
|
+
};
|
|
11
|
+
declare class XataPreparedQuery<T extends PreparedQueryConfig> extends PreparedQuery<T> {
|
|
12
|
+
private client;
|
|
13
|
+
private params;
|
|
14
|
+
private logger;
|
|
15
|
+
private fields;
|
|
16
|
+
private customResultMapper?;
|
|
17
|
+
static readonly [entityKind]: string;
|
|
18
|
+
private query;
|
|
19
|
+
constructor(client: XataClient, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: ((rows: unknown[][]) => T['execute']) | undefined);
|
|
20
|
+
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
|
|
21
|
+
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
|
|
22
|
+
values(placeholderValues?: Record<string, unknown> | undefined): Promise<T['values']>;
|
|
23
|
+
}
|
|
24
|
+
interface XataSessionOptions {
|
|
25
|
+
logger?: Logger;
|
|
26
|
+
}
|
|
27
|
+
declare class XataSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<XataQueryResultHKT, TFullSchema, TSchema> {
|
|
28
|
+
private client;
|
|
29
|
+
private schema;
|
|
30
|
+
private options;
|
|
31
|
+
static readonly [entityKind]: string;
|
|
32
|
+
private logger;
|
|
33
|
+
constructor(client: XataClient, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: XataSessionOptions);
|
|
34
|
+
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: (rows: unknown[][]) => T['execute']): PreparedQuery<T>;
|
|
35
|
+
query(query: string, params: unknown[]): Promise<QueryResult>;
|
|
36
|
+
queryObjects<T extends Record<string, unknown>>(query: string, params: unknown[]): Promise<QueryResult<T>>;
|
|
37
|
+
transaction<T>(_transaction: (tx: any) => Promise<T>, _config?: PgTransactionConfig | undefined): Promise<T>;
|
|
38
|
+
}
|
|
39
|
+
interface XataQueryResultHKT extends QueryResultHKT {
|
|
40
|
+
type: QueryResult<Assume<this['row'], Record<string, unknown>>[]>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type XataDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = PgDatabase<XataQueryResultHKT, TSchema>;
|
|
44
|
+
type XataClient = {
|
|
45
|
+
sql: SQLPluginResult;
|
|
46
|
+
};
|
|
47
|
+
declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: XataClient, config?: DrizzleConfig<TSchema>): XataDatabase<TSchema>;
|
|
48
|
+
|
|
49
|
+
declare function buildTable(schema: Schemas.Table): drizzle_orm_pg_core.PgTableWithColumns<{
|
|
50
|
+
name: string;
|
|
51
|
+
schema: undefined;
|
|
52
|
+
columns: {
|
|
53
|
+
[x: string]: drizzle_orm_pg_core.PgColumn<{
|
|
54
|
+
name: any;
|
|
55
|
+
tableName: string;
|
|
56
|
+
dataType: any;
|
|
57
|
+
columnType: any;
|
|
58
|
+
data: any;
|
|
59
|
+
driverParam: any;
|
|
60
|
+
notNull: boolean;
|
|
61
|
+
hasDefault: boolean;
|
|
62
|
+
enumValues: any;
|
|
63
|
+
baseColumn: drizzle_orm.Column<{
|
|
64
|
+
name: string;
|
|
65
|
+
tableName: string;
|
|
66
|
+
dataType: drizzle_orm.ColumnDataType;
|
|
67
|
+
columnType: string;
|
|
68
|
+
data: unknown;
|
|
69
|
+
driverParam: unknown;
|
|
70
|
+
notNull: false;
|
|
71
|
+
hasDefault: false;
|
|
72
|
+
enumValues: string[] | undefined;
|
|
73
|
+
baseColumn: never;
|
|
74
|
+
}, object, object>;
|
|
75
|
+
}, {}, {}>;
|
|
76
|
+
};
|
|
77
|
+
dialect: "pg";
|
|
78
|
+
}>;
|
|
79
|
+
type DrizzleModels<T extends readonly BaseSchema[]> = T extends never[] ? Record<string, Record<string, any>> : T extends readonly unknown[] ? T[number] extends {
|
|
80
|
+
name: string;
|
|
81
|
+
columns: readonly unknown[];
|
|
82
|
+
} ? {
|
|
83
|
+
[K in T[number]['name']]: ReturnType<typeof buildTable>;
|
|
84
|
+
} : never : never;
|
|
85
|
+
declare function buildModels<T extends readonly BaseSchema[]>(tables: T): DrizzleModels<T>;
|
|
86
|
+
|
|
87
|
+
export { type DrizzleModels, type XataClient, type XataDatabase, XataPreparedQuery, type XataQueryResultHKT, XataSession, type XataSessionOptions, buildModels, drizzle };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { is, Column, SQL, getTableName, fillPlaceholders, NoopLogger, entityKind, DefaultLogger, extractTablesRelationalConfig, createTableRelationsHelpers } from 'drizzle-orm';
|
|
2
|
+
import { PreparedQuery, PgSession, PgDialect, PgDatabase, text, pgTable, date, decimal, integer, boolean } from 'drizzle-orm/pg-core';
|
|
3
|
+
|
|
4
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
5
|
+
const nullifyMap = {};
|
|
6
|
+
const result = columns.reduce((result2, { path, field }, columnIndex) => {
|
|
7
|
+
let decoder;
|
|
8
|
+
if (is(field, Column)) {
|
|
9
|
+
decoder = field;
|
|
10
|
+
} else if (is(field, SQL)) {
|
|
11
|
+
decoder = field.decoder;
|
|
12
|
+
} else {
|
|
13
|
+
decoder = field.sql.decoder;
|
|
14
|
+
}
|
|
15
|
+
let node = result2;
|
|
16
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
17
|
+
if (pathChunkIndex < path.length - 1) {
|
|
18
|
+
if (!(pathChunk in node)) {
|
|
19
|
+
node[pathChunk] = {};
|
|
20
|
+
}
|
|
21
|
+
node = node[pathChunk];
|
|
22
|
+
} else {
|
|
23
|
+
const rawValue = row[columnIndex];
|
|
24
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
25
|
+
if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
|
|
26
|
+
const objectName = path[0];
|
|
27
|
+
if (!(objectName in nullifyMap)) {
|
|
28
|
+
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
29
|
+
} else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
30
|
+
nullifyMap[objectName] = false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result2;
|
|
36
|
+
}, {});
|
|
37
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
38
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
39
|
+
if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) {
|
|
40
|
+
result[objectName] = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
const exhaustiveCheck = (x) => {
|
|
47
|
+
throw new Error(`Unhandled discriminated union member: ${x}`);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var __defProp = Object.defineProperty;
|
|
51
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
|
+
var __publicField = (obj, key, value) => {
|
|
53
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
var _a, _b;
|
|
57
|
+
class XataPreparedQuery extends PreparedQuery {
|
|
58
|
+
constructor(client, queryString, params, logger, fields, name, customResultMapper) {
|
|
59
|
+
super();
|
|
60
|
+
this.client = client;
|
|
61
|
+
this.params = params;
|
|
62
|
+
this.logger = logger;
|
|
63
|
+
this.fields = fields;
|
|
64
|
+
this.customResultMapper = customResultMapper;
|
|
65
|
+
__publicField(this, "query");
|
|
66
|
+
this.query = {
|
|
67
|
+
name,
|
|
68
|
+
statement: queryString
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async execute(placeholderValues = {}) {
|
|
72
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
73
|
+
this.logger.logQuery(this.query.statement, params);
|
|
74
|
+
const { records } = await this.client.sql({
|
|
75
|
+
statement: this.query.statement,
|
|
76
|
+
params
|
|
77
|
+
});
|
|
78
|
+
const fields = this.fields ?? Object.keys(records[0]).map(
|
|
79
|
+
(key) => ({
|
|
80
|
+
path: [key],
|
|
81
|
+
field: {
|
|
82
|
+
sql: {
|
|
83
|
+
decoder: {
|
|
84
|
+
mapFromDriverValue: (value) => value
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
const rows = records.map((record) => fields.map((field) => record[field.path.join(".")]));
|
|
91
|
+
if (this.customResultMapper) {
|
|
92
|
+
return this.customResultMapper(rows);
|
|
93
|
+
}
|
|
94
|
+
return rows.map((row) => mapResultRow(fields, row, void 0));
|
|
95
|
+
}
|
|
96
|
+
async all(placeholderValues = {}) {
|
|
97
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
98
|
+
this.logger.logQuery(this.query.statement, params);
|
|
99
|
+
const { records } = await this.client.sql({
|
|
100
|
+
statement: this.query.statement,
|
|
101
|
+
params
|
|
102
|
+
});
|
|
103
|
+
return records;
|
|
104
|
+
}
|
|
105
|
+
async values(placeholderValues = {}) {
|
|
106
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
107
|
+
this.logger.logQuery(this.query.statement, params);
|
|
108
|
+
const { records } = await this.client.sql({
|
|
109
|
+
statement: this.query.statement,
|
|
110
|
+
params
|
|
111
|
+
});
|
|
112
|
+
return records;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
_a = entityKind;
|
|
116
|
+
__publicField(XataPreparedQuery, _a, "VercelPgPreparedQuery");
|
|
117
|
+
class XataSession extends PgSession {
|
|
118
|
+
constructor(client, dialect, schema, options = {}) {
|
|
119
|
+
super(dialect);
|
|
120
|
+
this.client = client;
|
|
121
|
+
this.schema = schema;
|
|
122
|
+
this.options = options;
|
|
123
|
+
__publicField(this, "logger");
|
|
124
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
125
|
+
}
|
|
126
|
+
prepareQuery(query, fields, name, customResultMapper) {
|
|
127
|
+
return new XataPreparedQuery(this.client, query.sql, query.params, this.logger, fields, name, customResultMapper);
|
|
128
|
+
}
|
|
129
|
+
async query(query, params) {
|
|
130
|
+
this.logger.logQuery(query, params);
|
|
131
|
+
return await this.client.sql({ statement: query, params });
|
|
132
|
+
}
|
|
133
|
+
async queryObjects(query, params) {
|
|
134
|
+
return this.client.sql({ statement: query, params });
|
|
135
|
+
}
|
|
136
|
+
async transaction(_transaction, _config) {
|
|
137
|
+
throw new Error("Transactions are not supported");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
_b = entityKind;
|
|
141
|
+
__publicField(XataSession, _b, "VercelPgSession");
|
|
142
|
+
|
|
143
|
+
function drizzle(client, config = {}) {
|
|
144
|
+
const dialect = new PgDialect();
|
|
145
|
+
let logger;
|
|
146
|
+
if (config.logger === true) {
|
|
147
|
+
logger = new DefaultLogger();
|
|
148
|
+
} else if (config.logger !== false) {
|
|
149
|
+
logger = config.logger;
|
|
150
|
+
}
|
|
151
|
+
let schema;
|
|
152
|
+
if (config.schema) {
|
|
153
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
154
|
+
schema = {
|
|
155
|
+
fullSchema: config.schema,
|
|
156
|
+
schema: tablesConfig.tables,
|
|
157
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const session = new XataSession(client, dialect, schema, { logger });
|
|
161
|
+
return new PgDatabase(dialect, session, schema);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function buildColumnType(column) {
|
|
165
|
+
switch (column.type) {
|
|
166
|
+
case "string":
|
|
167
|
+
case "text":
|
|
168
|
+
case "email":
|
|
169
|
+
case "link":
|
|
170
|
+
return text(column.name);
|
|
171
|
+
case "bool":
|
|
172
|
+
return boolean(column.name);
|
|
173
|
+
case "int":
|
|
174
|
+
return integer(column.name);
|
|
175
|
+
case "float":
|
|
176
|
+
return decimal(column.name);
|
|
177
|
+
case "datetime":
|
|
178
|
+
return date(column.name);
|
|
179
|
+
case "multiple":
|
|
180
|
+
case "object":
|
|
181
|
+
case "vector":
|
|
182
|
+
case "file[]":
|
|
183
|
+
case "file":
|
|
184
|
+
case "json":
|
|
185
|
+
throw new Error(`Unsupported column type: ${column.type}`);
|
|
186
|
+
default:
|
|
187
|
+
return exhaustiveCheck(column.type);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function buildColumn(column) {
|
|
191
|
+
let type = buildColumnType(column);
|
|
192
|
+
if (column.notNull) {
|
|
193
|
+
type = type.notNull();
|
|
194
|
+
}
|
|
195
|
+
if (column.unique) {
|
|
196
|
+
type = type.unique();
|
|
197
|
+
}
|
|
198
|
+
return type;
|
|
199
|
+
}
|
|
200
|
+
function buildTable(schema) {
|
|
201
|
+
const columns = schema.columns.map((column) => [column.name, buildColumn(column)]);
|
|
202
|
+
const definition = { id: text("id"), ...Object.fromEntries(columns) };
|
|
203
|
+
return pgTable(schema.name, definition);
|
|
204
|
+
}
|
|
205
|
+
function buildModels(tables) {
|
|
206
|
+
const entries = tables.map((table) => [table.name, buildTable(table)]);
|
|
207
|
+
return Object.fromEntries(entries);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { XataPreparedQuery, XataSession, buildModels, drizzle };
|
|
211
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/utils.ts","../src/session.ts","../src/driver.ts","../src/generate.ts"],"sourcesContent":["import { AnyColumn, Column, DriverValueDecoder, SQL, getTableName, is } from 'drizzle-orm';\n\ntype SelectedFieldsOrdered<TColumn extends Column> = {\n path: string[];\n field: TColumn | SQL | SQL.Aliased;\n}[];\n\nexport function mapResultRow<TResult>(\n columns: SelectedFieldsOrdered<AnyColumn>,\n row: unknown[],\n joinsNotNullableMap: Record<string, boolean> | undefined\n): TResult {\n // Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise\n const nullifyMap: Record<string, string | false> = {};\n\n const result = columns.reduce<Record<string, any>>((result, { path, field }, columnIndex) => {\n let decoder: DriverValueDecoder<unknown, unknown>;\n if (is(field, Column)) {\n decoder = field;\n } else if (is(field, SQL)) {\n decoder = (field as any).decoder;\n } else {\n decoder = (field as any).sql.decoder;\n }\n let node = result;\n for (const [pathChunkIndex, pathChunk] of path.entries()) {\n if (pathChunkIndex < path.length - 1) {\n if (!(pathChunk in node)) {\n node[pathChunk] = {};\n }\n node = node[pathChunk];\n } else {\n const rawValue = row[columnIndex]!;\n const value = (node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue));\n\n if (joinsNotNullableMap && is(field, Column) && path.length === 2) {\n const objectName = path[0]!;\n if (!(objectName in nullifyMap)) {\n nullifyMap[objectName] = value === null ? getTableName(field.table) : false;\n } else if (\n typeof nullifyMap[objectName] === 'string' &&\n nullifyMap[objectName] !== getTableName(field.table)\n ) {\n nullifyMap[objectName] = false;\n }\n }\n }\n }\n return result;\n }, {});\n\n // Nullify all nested objects from nullifyMap that are nullable\n if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {\n for (const [objectName, tableName] of Object.entries(nullifyMap)) {\n if (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {\n result[objectName] = null;\n }\n }\n }\n\n return result as TResult;\n}\n\nexport const exhaustiveCheck = (x: never): never => {\n throw new Error(`Unhandled discriminated union member: ${x}`);\n};\n","import {\n Assume,\n Logger,\n NoopLogger,\n Query,\n RelationalSchemaConfig,\n TablesRelationalConfig,\n entityKind,\n fillPlaceholders\n} from 'drizzle-orm';\nimport {\n PgDialect,\n PgSession,\n PgTransactionConfig,\n PreparedQuery,\n PreparedQueryConfig,\n QueryResultHKT,\n SelectedFieldsOrdered\n} from 'drizzle-orm/pg-core';\nimport { XataClient } from './driver';\nimport { mapResultRow } from './utils';\n\ntype QueryResult<T = Record<string, unknown>> = {\n records: T[];\n warning?: string;\n};\n\nexport class XataPreparedQuery<T extends PreparedQueryConfig> extends PreparedQuery<T> {\n static readonly [entityKind]: string = 'VercelPgPreparedQuery';\n\n private query: {\n name: string | undefined;\n statement: string;\n };\n\n constructor(\n private client: XataClient,\n queryString: string,\n private params: unknown[],\n private logger: Logger,\n private fields: SelectedFieldsOrdered | undefined,\n name: string | undefined,\n private customResultMapper?: (rows: unknown[][]) => T['execute']\n ) {\n super();\n\n this.query = {\n name,\n statement: queryString\n };\n }\n\n async execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n const params = fillPlaceholders(this.params, placeholderValues);\n\n this.logger.logQuery(this.query.statement, params);\n\n const { records } = await this.client.sql<Record<string, unknown>>({\n statement: this.query.statement,\n params\n });\n\n // FIXME: This is a hack, we should be able to get the fields from the query but SELECT * fails\n const fields =\n this.fields ??\n Object.keys(records[0]!).map(\n (key) =>\n ({\n path: [key],\n field: {\n sql: {\n decoder: {\n mapFromDriverValue: (value: unknown) => value\n }\n }\n }\n } as any)\n );\n\n const rows = records.map((record) => fields.map((field) => record[field.path.join('.')]));\n\n if (this.customResultMapper) {\n return this.customResultMapper(rows);\n }\n\n return rows.map((row) => mapResultRow<T['execute']>(fields, row, undefined));\n }\n\n async all(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n const params = fillPlaceholders(this.params, placeholderValues);\n this.logger.logQuery(this.query.statement, params);\n\n const { records } = await this.client.sql({\n statement: this.query.statement,\n params\n });\n\n return records;\n }\n\n async values(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['values']> {\n const params = fillPlaceholders(this.params, placeholderValues);\n this.logger.logQuery(this.query.statement, params);\n\n const { records } = await this.client.sql({\n statement: this.query.statement,\n params\n });\n\n return records;\n }\n}\n\nexport interface XataSessionOptions {\n logger?: Logger;\n}\n\nexport class XataSession<\n TFullSchema extends Record<string, unknown>,\n TSchema extends TablesRelationalConfig\n> extends PgSession<XataQueryResultHKT, TFullSchema, TSchema> {\n static readonly [entityKind]: string = 'VercelPgSession';\n\n private logger: Logger;\n\n constructor(\n private client: XataClient,\n dialect: PgDialect,\n private schema: RelationalSchemaConfig<TSchema> | undefined,\n private options: XataSessionOptions = {}\n ) {\n super(dialect);\n this.logger = options.logger ?? new NoopLogger();\n }\n\n prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n query: Query,\n fields: SelectedFieldsOrdered | undefined,\n name: string | undefined,\n customResultMapper?: (rows: unknown[][]) => T['execute']\n ): PreparedQuery<T> {\n return new XataPreparedQuery(this.client, query.sql, query.params, this.logger, fields, name, customResultMapper);\n }\n\n async query(query: string, params: unknown[]): Promise<QueryResult> {\n this.logger.logQuery(query, params);\n return await this.client.sql({ statement: query, params });\n }\n\n async queryObjects<T extends Record<string, unknown>>(query: string, params: unknown[]): Promise<QueryResult<T>> {\n return this.client.sql({ statement: query, params });\n }\n\n override async transaction<T>(\n _transaction: (tx: any) => Promise<T>,\n _config?: PgTransactionConfig | undefined\n ): Promise<T> {\n throw new Error('Transactions are not supported');\n }\n}\n\nexport interface XataQueryResultHKT extends QueryResultHKT {\n type: QueryResult<Assume<this['row'], Record<string, unknown>>[]>;\n}\n","import { SQLPluginResult } from '@xata.io/client';\nimport {\n DefaultLogger,\n DrizzleConfig,\n RelationalSchemaConfig,\n TablesRelationalConfig,\n createTableRelationsHelpers,\n extractTablesRelationalConfig\n} from 'drizzle-orm';\nimport { PgDatabase, PgDialect } from 'drizzle-orm/pg-core';\nimport { XataQueryResultHKT, XataSession } from './session';\n\nexport type XataDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = PgDatabase<\n XataQueryResultHKT,\n TSchema\n>;\n\nexport type XataClient = {\n sql: SQLPluginResult;\n};\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n client: XataClient,\n config: DrizzleConfig<TSchema> = {}\n): XataDatabase<TSchema> {\n const dialect = new PgDialect();\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(config.schema, createTableRelationsHelpers);\n schema = {\n fullSchema: config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap\n };\n }\n\n const session = new XataSession(client, dialect, schema, { logger });\n return new PgDatabase(dialect, session, schema) as XataDatabase<TSchema>;\n}\n","import { BaseSchema, Schemas } from '@xata.io/client';\nimport { boolean, date, decimal, integer, pgTable, text } from 'drizzle-orm/pg-core';\nimport { exhaustiveCheck } from './utils';\n\nfunction buildColumnType(column: Schemas.Column) {\n switch (column.type) {\n case 'string':\n case 'text':\n case 'email':\n case 'link':\n return text(column.name);\n case 'bool':\n return boolean(column.name);\n case 'int':\n return integer(column.name);\n case 'float':\n return decimal(column.name);\n case 'datetime':\n return date(column.name);\n case 'multiple':\n case 'object':\n case 'vector':\n case 'file[]':\n case 'file':\n case 'json':\n throw new Error(`Unsupported column type: ${column.type}`);\n default:\n return exhaustiveCheck(column.type);\n }\n}\n\nfunction buildColumn(column: Schemas.Column) {\n let type = buildColumnType(column);\n\n if (column.notNull) {\n type = type.notNull();\n }\n\n if (column.unique) {\n type = type.unique();\n }\n\n return type;\n}\n\nfunction buildTable(schema: Schemas.Table) {\n const columns = schema.columns.map((column) => [column.name, buildColumn(column)]);\n const definition = { id: text('id'), ...Object.fromEntries(columns) };\n return pgTable(schema.name, definition);\n}\n\nexport type DrizzleModels<T extends readonly BaseSchema[]> = T extends never[]\n ? Record<string, Record<string, any>>\n : T extends readonly unknown[]\n ? T[number] extends { name: string; columns: readonly unknown[] }\n ? {\n [K in T[number]['name']]: ReturnType<typeof buildTable>;\n }\n : never\n : never;\n\nexport function buildModels<T extends readonly BaseSchema[]>(tables: T): DrizzleModels<T> {\n const entries = tables.map((table) => [table.name, buildTable(table as Schemas.Table)]);\n return Object.fromEntries(entries);\n}\n"],"names":["result"],"mappings":";;;AAOgB,SAAA,YAAA,CACd,OACA,EAAA,GAAA,EACA,mBACS,EAAA;AAET,EAAA,MAAM,aAA6C,EAAC,CAAA;AAEpD,EAAM,MAAA,MAAA,GAAS,QAAQ,MAA4B,CAAA,CAACA,SAAQ,EAAE,IAAA,EAAM,KAAM,EAAA,EAAG,WAAgB,KAAA;AAC3F,IAAI,IAAA,OAAA,CAAA;AACJ,IAAI,IAAA,EAAA,CAAG,KAAO,EAAA,MAAM,CAAG,EAAA;AACrB,MAAU,OAAA,GAAA,KAAA,CAAA;AAAA,KACD,MAAA,IAAA,EAAA,CAAG,KAAO,EAAA,GAAG,CAAG,EAAA;AACzB,MAAA,OAAA,GAAW,KAAc,CAAA,OAAA,CAAA;AAAA,KACpB,MAAA;AACL,MAAA,OAAA,GAAW,MAAc,GAAI,CAAA,OAAA,CAAA;AAAA,KAC/B;AACA,IAAA,IAAI,IAAOA,GAAAA,OAAAA,CAAAA;AACX,IAAA,KAAA,MAAW,CAAC,cAAgB,EAAA,SAAS,CAAK,IAAA,IAAA,CAAK,SAAW,EAAA;AACxD,MAAI,IAAA,cAAA,GAAiB,IAAK,CAAA,MAAA,GAAS,CAAG,EAAA;AACpC,QAAI,IAAA,EAAE,aAAa,IAAO,CAAA,EAAA;AACxB,UAAK,IAAA,CAAA,SAAS,IAAI,EAAC,CAAA;AAAA,SACrB;AACA,QAAA,IAAA,GAAO,KAAK,SAAS,CAAA,CAAA;AAAA,OAChB,MAAA;AACL,QAAM,MAAA,QAAA,GAAW,IAAI,WAAW,CAAA,CAAA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OAAQ,EAAA,CAAA;AAAA,GACtB;AAEA,EAAA,IAAI,OAAO,MAAQ,EAAA;AACjB,IAAA,IAAA,GAAO,KAAK,MAAO,EAAA,CAAA;AAAA,GACrB;AAEA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAEA,SAAS,WAAW,MAAuB,EAAA;AACzC,EAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,GAAA,CAAI,CAAC,MAAA,KAAW,CAAC,MAAA,CAAO,IAAM,EAAA,WAAA,CAAY,MAAM,CAAC,CAAC,CAAA,CAAA;AACjF,EAAM,MAAA,UAAA,GAAa,EAAE,EAAA,EAAI,IAAK,CAAA,IAAI,GAAG,GAAG,MAAA,CAAO,WAAY,CAAA,OAAO,CAAE,EAAA,CAAA;AACpE,EAAO,OAAA,OAAA,CAAQ,MAAO,CAAA,IAAA,EAAM,UAAU,CAAA,CAAA;AACxC,CAAA;AAYO,SAAS,YAA6C,MAA6B,EAAA;AACxF,EAAM,MAAA,OAAA,GAAU,MAAO,CAAA,GAAA,CAAI,CAAC,KAAA,KAAU,CAAC,KAAA,CAAM,IAAM,EAAA,UAAA,CAAW,KAAsB,CAAC,CAAC,CAAA,CAAA;AACtF,EAAO,OAAA,MAAA,CAAO,YAAY,OAAO,CAAA,CAAA;AACnC;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xata.io/drizzle",
|
|
3
|
+
"version": "0.0.0-alpha.v0e4f4d5",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/xataio/client-ts/issues"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@xata.io/client": "0.0.0-alpha.v0e4f4d5"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"drizzle-orm": "^0.28.5"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"drizzle-orm": "^0.28.5"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rimraf dist && rollup -c",
|
|
31
|
+
"tsc": "tsc --noEmit"
|
|
32
|
+
}
|
|
33
|
+
}
|