drizzle-orm 0.12.0-beta.9 → 0.13.1-03f651b
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/LICENSE +201 -0
- package/README.md +51 -0
- package/alias.js.map +1 -1
- package/column.js.map +1 -1
- package/connection.d.ts +10 -0
- package/connection.js +25 -30
- package/connection.js.map +1 -1
- package/operations.d.ts +1 -2
- package/package.json +15 -34
- package/query-promise.d.ts +7 -0
- package/query-promise.js +27 -0
- package/query-promise.js.map +1 -0
- package/sql/expressions/conditions.d.ts +11 -11
- package/sql/expressions/conditions.js +2 -2
- package/sql/expressions/conditions.js.map +1 -1
- package/sql/index.d.ts +17 -5
- package/sql/index.js +34 -6
- package/sql/index.js.map +1 -1
- package/utils.d.ts +76 -2
- package/utils.js +20 -14
- package/utils.js.map +1 -1
- package/branded-types.d.ts +0 -18
- package/branded-types.js +0 -6
- package/branded-types.js.map +0 -1
- package/readme.md +0 -22
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,51 @@
|
|
|
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/dw/drizzle-orm">
|
|
4
|
+
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/drizzle-orm">
|
|
5
|
+
<a href="https://discord.gg/yfjTbVXMW4"><img alt="Discord" src="https://img.shields.io/discord/1043890932593987624"></a>
|
|
6
|
+
<img alt="NPM" src="https://img.shields.io/npm/l/drizzle-orm">
|
|
7
|
+
<h6><i>If you know SQL, you know Drizzle ORM</i></h6>
|
|
8
|
+
<hr />
|
|
9
|
+
</div>
|
|
10
|
+
|
|
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
|
+
|
|
13
|
+
The ORM main philosophy is "If you know SQL, you know Drizzle ORM". We follow the SQL-like syntax whenever possible, are strongly typed ground top and fail at compile time, not in runtime.
|
|
14
|
+
|
|
15
|
+
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).
|
|
16
|
+
|
|
17
|
+
### Feature list
|
|
18
|
+
|
|
19
|
+
- Full type safety
|
|
20
|
+
- [Smart automated migrations generation](https://github.com/drizzle-team/drizzle-kit-mirror)
|
|
21
|
+
- No ORM learning curve
|
|
22
|
+
- SQL-like syntax for table definitions and queries
|
|
23
|
+
- Best in class fully typed joins
|
|
24
|
+
- Fully typed partial and non-partial selects of any complexity
|
|
25
|
+
- Auto-inferring of TS types for DB models for selections and insertions separately
|
|
26
|
+
- Zero dependencies
|
|
27
|
+
|
|
28
|
+
| Database | Support | 📄 |
|
|
29
|
+
|:------------|:-------:|:---|
|
|
30
|
+
| PostgreSQL | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-pg)|
|
|
31
|
+
| MySQL | ⏳ | |
|
|
32
|
+
| SQLite | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-sqlite)|
|
|
33
|
+
| DynamoDB | ⏳ | |
|
|
34
|
+
| MS SQL | ⏳ | |
|
|
35
|
+
| CockroachDB | ⏳ | |
|
|
36
|
+
|
|
37
|
+
### Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# postgresql
|
|
41
|
+
npm install drizzle-orm drizzle-orm-pg
|
|
42
|
+
npm install -D drizzle-kit
|
|
43
|
+
|
|
44
|
+
# mysql
|
|
45
|
+
npm install drizzle-orm drizzle-orm-mysql
|
|
46
|
+
npm install -D drizzle-kit
|
|
47
|
+
|
|
48
|
+
# sqlite
|
|
49
|
+
npm install drizzle-orm drizzle-orm-sqlite
|
|
50
|
+
npm install -D drizzle-kit
|
|
51
|
+
```
|
package/alias.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alias.js","sourceRoot":"","sources":["../src/alias.ts"],"names":[],"mappings":";;;AAAA,qCAA6C;AAC7C,mCAAgC;AAEhC,MAAa,uBAAuB;IACnC,
|
|
1
|
+
{"version":3,"file":"alias.js","sourceRoot":"","sources":["../src/alias.ts"],"names":[],"mappings":";;;AAAA,qCAA6C;AAC7C,mCAAgC;AAEhC,MAAa,uBAAuB;IACnC,YAAoB,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAEpC,GAAG,CAAC,SAAkB,EAAE,IAAqB,EAAE,QAAa;QAC3D,IAAI,IAAI,KAAK,OAAO,EAAE;YACrB,OAAO,IAAI,CAAC,KAAK,CAAC;SAClB;QACD,OAAO,SAAS,CAAC,IAAqB,CAAC,CAAC;IACzC,CAAC;CACD;AATD,0DASC;AAED,MAAa,sBAAsB;IAClC,YAAoB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAErC,GAAG,CAAC,QAAe,EAAE,IAAqB,EAAE,QAAa;QACxD,IAAI,IAAI,KAAK,aAAK,CAAC,MAAM,CAAC,IAAI,EAAE;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC;SAClB;QACD,IAAI,IAAI,KAAK,aAAK,CAAC,MAAM,CAAC,OAAO,EAAE;YAClC,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/C,IAAI,CAAC,OAAO,EAAE;gBACb,OAAO,OAAO,CAAC;aACf;YAED,MAAM,cAAc,GAA2B,EAAE,CAAC;YAElD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBAChC,cAAc,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,CAC9B,OAAO,CAAC,GAAG,CAAE,EACb,IAAI,uBAAuB,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CACtD,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,cAAc,CAAC;SACtB;QAED,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAmB,CAAC,CAAC;QAC5C,IAAI,KAAK,YAAY,eAAM,EAAE;YAC5B,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,uBAAuB,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;SAChF;QAED,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAhCD,wDAgCC"}
|
package/column.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column.js","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"column.js","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":";;;AAcA,kCAAkC;AAClC,+BAA+B;AAC/B,8CAA8C;AAC9C,kDAAkD;AAElD;;;;EAIE;AACF,MAAsB,MAAM;IAe3B,YAAqB,KAA4B,EAAE,OAA4C;QAA1E,UAAK,GAAL,KAAK,CAAuB;QAChD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;IAC1C,CAAC;IAID,kBAAkB,CAAC,KAAuB;QACzC,OAAO,KAAY,CAAC;IACrB,CAAC;IAED,gBAAgB,CAAC,KAAgB;QAChC,OAAO,KAAY,CAAC;IACrB,CAAC;CACD;AA/BD,wBA+BC"}
|
package/connection.d.ts
CHANGED
|
@@ -6,7 +6,17 @@ export declare type MigrationMeta = {
|
|
|
6
6
|
export interface Logger {
|
|
7
7
|
logQuery(query: string, params: unknown[]): void;
|
|
8
8
|
}
|
|
9
|
+
export interface LogWriter {
|
|
10
|
+
write(message: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class ConsoleLogWriter implements LogWriter {
|
|
13
|
+
write(message: string): void;
|
|
14
|
+
}
|
|
9
15
|
export declare class DefaultLogger implements Logger {
|
|
16
|
+
readonly writer: LogWriter;
|
|
17
|
+
constructor(config?: {
|
|
18
|
+
writer: LogWriter;
|
|
19
|
+
});
|
|
10
20
|
logQuery(query: string, params: unknown[]): void;
|
|
11
21
|
}
|
|
12
22
|
export declare class NoopLogger implements Logger {
|
package/connection.js
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.readMigrationFiles = exports.NoopLogger = exports.DefaultLogger = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
exports.readMigrationFiles = exports.NoopLogger = exports.DefaultLogger = exports.ConsoleLogWriter = void 0;
|
|
4
|
+
class ConsoleLogWriter {
|
|
5
|
+
write(message) {
|
|
6
|
+
console.log(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.ConsoleLogWriter = ConsoleLogWriter;
|
|
30
10
|
class DefaultLogger {
|
|
11
|
+
constructor(config = { writer: new ConsoleLogWriter() }) {
|
|
12
|
+
this.writer = config.writer;
|
|
13
|
+
}
|
|
31
14
|
logQuery(query, params) {
|
|
32
|
-
|
|
15
|
+
const stringifiedParams = params.map((p) => {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.stringify(p);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return String(p);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(', ')}]` : '';
|
|
24
|
+
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
33
25
|
}
|
|
34
26
|
}
|
|
35
27
|
exports.DefaultLogger = DefaultLogger;
|
|
@@ -38,6 +30,9 @@ class NoopLogger {
|
|
|
38
30
|
}
|
|
39
31
|
exports.NoopLogger = NoopLogger;
|
|
40
32
|
function readMigrationFiles(config) {
|
|
33
|
+
const fs = require('fs');
|
|
34
|
+
const crypto = require('crypto');
|
|
35
|
+
const path = require('path');
|
|
41
36
|
let migrationFolderTo;
|
|
42
37
|
if (typeof config === 'string') {
|
|
43
38
|
const configAsString = fs.readFileSync(path.resolve('.', config), 'utf8');
|
|
@@ -50,9 +45,9 @@ function readMigrationFiles(config) {
|
|
|
50
45
|
if (!migrationFolderTo) {
|
|
51
46
|
throw Error('no migration folder defined');
|
|
52
47
|
}
|
|
53
|
-
const
|
|
48
|
+
const files = fs.readdirSync(migrationFolderTo);
|
|
54
49
|
const migrationQueries = [];
|
|
55
|
-
for (const migrationFolder of
|
|
50
|
+
for (const migrationFolder of files) {
|
|
56
51
|
if (migrationFolder === '.DS_Store') {
|
|
57
52
|
continue;
|
|
58
53
|
}
|
package/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;AAUA,MAAa,gBAAgB;IAC5B,KAAK,CAAC,OAAe;QACpB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACD;AAJD,4CAIC;AAED,MAAa,aAAa;IAGzB,YAAY,SAAgC,EAAE,MAAM,EAAE,IAAI,gBAAgB,EAAE,EAAE;QAC7E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,QAAQ,CAAC,KAAa,EAAE,MAAiB;QACxC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC1C,IAAI;gBACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;aACzB;YAAC,OAA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AC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC7D,CAAC,CAAC;KACH;IAED,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAjDD,gDAiDC"}
|
package/operations.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-orm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1-03f651b",
|
|
4
4
|
"description": "Drizzle ORM package for SQL databases",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -21,56 +21,37 @@
|
|
|
21
21
|
"sql",
|
|
22
22
|
"typescript"
|
|
23
23
|
],
|
|
24
|
-
"author": "",
|
|
24
|
+
"author": "Drizzle Team",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/
|
|
27
|
+
"url": "https://github.com/drizzle-team/drizzle-orm/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://github.com/
|
|
29
|
+
"homepage": "https://github.com/drizzle-team/drizzle-orm#readme",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"drizzle-orm-mysql": ">=0.12
|
|
32
|
-
"drizzle-orm-pg": ">=0.
|
|
33
|
-
"
|
|
34
|
-
"pg": ">=8 <9",
|
|
35
|
-
"sqlite3": ">=5 <6"
|
|
31
|
+
"drizzle-orm-mysql": ">=0.12 <0.13",
|
|
32
|
+
"drizzle-orm-pg": ">=0.13 <0.14",
|
|
33
|
+
"drizzle-orm-sqlite": ">=0.13 <0.14"
|
|
36
34
|
},
|
|
37
35
|
"peerDependenciesMeta": {
|
|
38
|
-
"
|
|
39
|
-
"optional": true
|
|
40
|
-
},
|
|
41
|
-
"pg": {
|
|
42
|
-
"optional": true
|
|
43
|
-
},
|
|
44
|
-
"sqlite3": {
|
|
36
|
+
"drizzle-orm-mysql": {
|
|
45
37
|
"optional": true
|
|
46
38
|
},
|
|
47
39
|
"drizzle-orm-pg": {
|
|
48
40
|
"optional": true
|
|
49
41
|
},
|
|
50
|
-
"drizzle-orm-
|
|
42
|
+
"drizzle-orm-sqlite": {
|
|
51
43
|
"optional": true
|
|
52
44
|
}
|
|
53
45
|
},
|
|
54
46
|
"devDependencies": {
|
|
55
|
-
"@types/node": "
|
|
56
|
-
"@types/pg": "^8.6.1",
|
|
57
|
-
"@types/sqlite3": "^3.1.8",
|
|
58
|
-
"mysql2": "^2.3.3",
|
|
59
|
-
"pg": "^8.6.0",
|
|
60
|
-
"resolve-tspaths": "^0.7.0",
|
|
61
|
-
"sqlite3": "^5.0.8",
|
|
62
|
-
"ts-node": "^10.8.2",
|
|
63
|
-
"typescript": "^4.8.4",
|
|
64
|
-
"uvu": "^0.5.6"
|
|
65
|
-
},
|
|
66
|
-
"dependencies": {
|
|
67
|
-
"type-fest": "^2.16.0"
|
|
47
|
+
"@types/node": "^18.11.9"
|
|
68
48
|
},
|
|
69
49
|
"scripts": {
|
|
70
|
-
"build": "tsc",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"release
|
|
50
|
+
"build": "tsc -p tsconfig.build.json",
|
|
51
|
+
"test:types": "echo WARN: No tests defined!",
|
|
52
|
+
"pack": "cp ../README.md package.json dist/ && (cd dist && pnpm pack --pack-destination ..) && rm -f package.tgz && mv *.tgz package.tgz",
|
|
53
|
+
"release": "pnpm build && pnpm run pack && pnpm run publish",
|
|
54
|
+
"release:beta": "pnpm build && pnpm run pack && pnpm run publish --tag beta",
|
|
74
55
|
"build:int": "pnpm build && pnpm run pack"
|
|
75
56
|
}
|
|
76
57
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare abstract class QueryPromise<T> implements Promise<T> {
|
|
2
|
+
[Symbol.toStringTag]: string;
|
|
3
|
+
catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
|
|
4
|
+
finally(onFinally?: (() => void) | null | undefined): Promise<T>;
|
|
5
|
+
then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
6
|
+
abstract execute(): Promise<T>;
|
|
7
|
+
}
|
package/query-promise.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.QueryPromise = void 0;
|
|
5
|
+
class QueryPromise {
|
|
6
|
+
constructor() {
|
|
7
|
+
this[_a] = 'QueryPromise';
|
|
8
|
+
}
|
|
9
|
+
catch(onRejected) {
|
|
10
|
+
return this.then(undefined, onRejected);
|
|
11
|
+
}
|
|
12
|
+
finally(onFinally) {
|
|
13
|
+
return this.then((value) => {
|
|
14
|
+
onFinally === null || onFinally === void 0 ? void 0 : onFinally();
|
|
15
|
+
return value;
|
|
16
|
+
}, (reason) => {
|
|
17
|
+
onFinally === null || onFinally === void 0 ? void 0 : onFinally();
|
|
18
|
+
return Promise.reject(reason);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
then(onFulfilled, onRejected) {
|
|
22
|
+
return this.execute().then(onFulfilled, onRejected);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.QueryPromise = QueryPromise;
|
|
26
|
+
_a = Symbol.toStringTag;
|
|
27
|
+
//# sourceMappingURL=query-promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-promise.js","sourceRoot":"","sources":["../src/query-promise.ts"],"names":[],"mappings":";;;;AAAA,MAAsB,YAAY;IAAlC;QACC,QAAoB,GAAG,cAAc,CAAC;IA6BvC,CAAC;IA3BA,KAAK,CACJ,UAAiF;QAEjF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,SAA2C;QAClD,OAAO,IAAI,CAAC,IAAI,CACf,CAAC,KAAK,EAAE,EAAE;YACT,SAAS,aAAT,SAAS,uBAAT,SAAS,EAAI,CAAC;YACd,OAAO,KAAK,CAAC;QACd,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;YACV,SAAS,aAAT,SAAS,uBAAT,SAAS,EAAI,CAAC;YACd,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC,CACD,CAAC;IACH,CAAC;IAED,IAAI,CACH,WAAiF,EACjF,UAAmF;QAEnF,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;CAGD;AA9BD,oCA8BC;KA7BC,MAAM,CAAC,WAAW"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { AnyColumn, GetColumnData } from '../../column';
|
|
2
|
-
import { SQL, SQLWrapper } from '..';
|
|
3
|
-
export declare function eq<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn, 'raw'>): SQL;
|
|
2
|
+
import { Placeholder, SQL, SQLWrapper } from '..';
|
|
3
|
+
export declare function eq<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn, 'raw'> | Placeholder): SQL;
|
|
4
4
|
export declare function eq(left: AnyColumn, right: AnyColumn): SQL;
|
|
5
|
-
export declare function ne<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn>): SQL;
|
|
5
|
+
export declare function ne<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn> | Placeholder): SQL;
|
|
6
6
|
export declare function ne(left: AnyColumn, right: AnyColumn): SQL;
|
|
7
7
|
export declare function and(...conditions: (SQL | undefined)[]): SQL | undefined;
|
|
8
8
|
export declare function or(...conditions: (SQL | undefined)[]): SQL | undefined;
|
|
9
9
|
export declare function not(condition: SQL): SQL;
|
|
10
|
-
export declare function gt<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn>): SQL;
|
|
10
|
+
export declare function gt<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn> | Placeholder): SQL;
|
|
11
11
|
export declare function gt(left: AnyColumn, right: AnyColumn): SQL;
|
|
12
|
-
export declare function gte<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn>): SQL;
|
|
12
|
+
export declare function gte<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn> | Placeholder): SQL;
|
|
13
13
|
export declare function gte(left: AnyColumn, right: AnyColumn): SQL;
|
|
14
|
-
export declare function lt<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn>): SQL;
|
|
14
|
+
export declare function lt<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn> | Placeholder): SQL;
|
|
15
15
|
export declare function lt(left: AnyColumn, right: AnyColumn): SQL;
|
|
16
|
-
export declare function lte<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn>): SQL;
|
|
16
|
+
export declare function lte<TColumn extends AnyColumn>(column: TColumn, value: GetColumnData<TColumn> | Placeholder): SQL;
|
|
17
17
|
export declare function lte(left: AnyColumn, right: AnyColumn): SQL;
|
|
18
|
-
export declare function inArray<TColumn extends AnyColumn>(column: TColumn, values: GetColumnData<TColumn>[]): SQL;
|
|
18
|
+
export declare function inArray<TColumn extends AnyColumn>(column: TColumn, values: (GetColumnData<TColumn> | Placeholder)[]): SQL;
|
|
19
19
|
export declare function inArray(column: AnyColumn, subquery: SQLWrapper): SQL;
|
|
20
|
-
export declare function notInArray<TColumn extends AnyColumn>(column: TColumn, values: GetColumnData<TColumn>[]): SQL;
|
|
20
|
+
export declare function notInArray<TColumn extends AnyColumn>(column: TColumn, values: (GetColumnData<TColumn> | Placeholder)[]): SQL;
|
|
21
21
|
export declare function notInArray(column: AnyColumn, subquery: SQLWrapper): SQL;
|
|
22
22
|
export declare function isNull(column: AnyColumn<{
|
|
23
23
|
notNull: false;
|
|
@@ -25,8 +25,8 @@ export declare function isNull(column: AnyColumn<{
|
|
|
25
25
|
export declare function isNotNull(column: AnyColumn): SQL;
|
|
26
26
|
export declare function exists(subquery: SQLWrapper): SQL;
|
|
27
27
|
export declare function notExists(subquery: SQLWrapper): SQL;
|
|
28
|
-
export declare function between<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'
|
|
29
|
-
export declare function notBetween<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'
|
|
28
|
+
export declare function between<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'> | Placeholder, max: GetColumnData<TColumn, 'raw'> | Placeholder): SQL;
|
|
29
|
+
export declare function notBetween<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'> | Placeholder, max: GetColumnData<TColumn, 'raw'> | Placeholder): SQL;
|
|
30
30
|
export declare function like(column: AnyColumn, value: string): SQL;
|
|
31
31
|
export declare function notLike(column: AnyColumn, value: string): SQL;
|
|
32
32
|
export declare function ilike(column: AnyColumn, value: string): SQL;
|
|
@@ -4,7 +4,7 @@ exports.notIlike = exports.ilike = exports.notLike = exports.like = exports.notB
|
|
|
4
4
|
const column_1 = require("../../column");
|
|
5
5
|
const __1 = require("..");
|
|
6
6
|
function bindIfParam(value, column) {
|
|
7
|
-
if (value instanceof column_1.Column) {
|
|
7
|
+
if (value instanceof column_1.Column || value instanceof __1.Placeholder) {
|
|
8
8
|
return value;
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
@@ -84,7 +84,7 @@ function inArray(column, values) {
|
|
|
84
84
|
if (values.length === 0) {
|
|
85
85
|
throw new Error('inArray requires at least one value');
|
|
86
86
|
}
|
|
87
|
-
return (0, __1.sql) `${column} in ${values.map((v) =>
|
|
87
|
+
return (0, __1.sql) `${column} in ${values.map((v) => bindIfParam(v, column))}`;
|
|
88
88
|
}
|
|
89
89
|
exports.inArray = inArray;
|
|
90
90
|
function notInArray(column, values) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../../../src/sql/expressions/conditions.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../../../src/sql/expressions/conditions.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAChE,0BAA4E;AAE5E,SAAS,WAAW,CAAC,KAAc,EAAE,MAAiB;IACrD,IAAI,KAAK,YAAY,eAAM,IAAI,KAAK,YAAY,eAAW,EAAE;QAC5D,OAAO,KAAK,CAAC;KACb;SAAM;QACN,OAAO,IAAI,SAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KAChC;AACF,CAAC;AAID,SAAgB,EAAE,CAAC,IAAe,EAAE,KAAc;IACjD,OAAO,IAAA,OAAG,EAAA,GAAG,IAAI,MAAM,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;AACnD,CAAC;AAFD,gBAEC;AAID,SAAgB,EAAE,CAAC,IAAe,EAAE,KAAc;IACjD,OAAO,IAAA,OAAG,EAAA,GAAG,IAAI,OAAO,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;AACpD,CAAC;AAFD,gBAEC;AAED,SAAgB,GAAG,CAAC,GAAG,UAA+B;IACrD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,OAAO,SAAS,CAAC;KACjB;IAED,MAAM,MAAM,GAAU,CAAC,OAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACrC,UAAU;SACR,MAAM,CAAC,CAAC,CAAC,EAAqC,EAAE,CAAC,OAAO,CAAC,KAAK,WAAW,CAAC;SAC1E,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;QAC7B,IAAI,KAAK,KAAK,CAAC,EAAE;YAChB,MAAM,CAAC,IAAI,CAAC,SAAS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AED,SAAgB,KAAK,CAAC,MAAiB,EAAE,KAAa;IACrD,OAAO,IAAA,OAAG,EAAA,GAAG,MAAM,UAAU,KAAK,EAAE,CAAC;AACtC,CAAC;AAFD,sBAEC;AAED,SAAgB,QAAQ,CAAC,MAAiB,EAAE,KAAa;IACxD,OAAO,IAAA,OAAG,EAAA,GAAG,MAAM,cAAc,KAAK,EAAE,CAAC;AAC1C,CAAC;AAFD,4BAEC"}
|
package/sql/index.d.ts
CHANGED
|
@@ -7,24 +7,24 @@ import { Table } from '../table';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class FakePrimitiveParam {
|
|
9
9
|
}
|
|
10
|
-
export declare type Chunk = string | Table | AnyColumn | Name | Param;
|
|
10
|
+
export declare type Chunk = string | Table | AnyColumn | Name | Param | Placeholder;
|
|
11
11
|
export interface BuildQueryConfig {
|
|
12
12
|
escapeName(name: string): string;
|
|
13
13
|
escapeParam(num: number, value: unknown): string;
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
15
|
+
export interface Query {
|
|
16
16
|
sql: string;
|
|
17
17
|
params: unknown[];
|
|
18
18
|
}
|
|
19
19
|
export interface SQLWrapper {
|
|
20
20
|
getSQL(): SQL;
|
|
21
21
|
}
|
|
22
|
-
export declare function isSQLWrapper(
|
|
22
|
+
export declare function isSQLWrapper(value: unknown): value is SQLWrapper;
|
|
23
23
|
export declare class SQL implements SQLWrapper {
|
|
24
24
|
readonly queryChunks: Chunk[];
|
|
25
25
|
protected $brand: 'SQL';
|
|
26
26
|
constructor(queryChunks: Chunk[]);
|
|
27
|
-
toQuery({ escapeName, escapeParam }: BuildQueryConfig):
|
|
27
|
+
toQuery({ escapeName, escapeParam }: BuildQueryConfig): Query;
|
|
28
28
|
getSQL(): SQL;
|
|
29
29
|
as<TDecoder extends DriverValueDecoder<any, any> | DriverValueDecoder<any, any>['mapFromDriverValue']>(decoder: TDecoder): SQLResponse<GetDecoderColumnData<TDecoder>>;
|
|
30
30
|
as<TData>(): SQLResponse<TData>;
|
|
@@ -38,6 +38,10 @@ export declare class Name {
|
|
|
38
38
|
protected brand: 'Name';
|
|
39
39
|
constructor(value: string);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Any DB name (table, column, index etc.)
|
|
43
|
+
*/
|
|
44
|
+
export declare function name(value: string): Name;
|
|
41
45
|
export interface DriverValueDecoder<TData, TDriverParam> {
|
|
42
46
|
mapFromDriverValue(value: TDriverParam): TData;
|
|
43
47
|
}
|
|
@@ -61,7 +65,7 @@ export declare class Param<TDataType = unknown, TDriverParamType = TDataType> {
|
|
|
61
65
|
constructor(value: TDataType, encoder?: DriverValueEncoder<TDataType, TDriverParamType>);
|
|
62
66
|
}
|
|
63
67
|
export declare function param<TData, TDriver>(value: TData, encoder?: DriverValueEncoder<TData, TDriver>): Param<TData, TDriver>;
|
|
64
|
-
export declare type SQLSourceParam = SQLSourceParam[] | SQLWrapper | SQL | Table | AnyColumn | Param | Name | undefined | FakePrimitiveParam;
|
|
68
|
+
export declare type SQLSourceParam = SQLSourceParam[] | SQLWrapper | SQL | Table | AnyColumn | Param | Name | undefined | FakePrimitiveParam | Placeholder;
|
|
65
69
|
export declare function sql(strings: TemplateStringsArray, ...params: any[]): SQL;
|
|
66
70
|
export declare namespace sql {
|
|
67
71
|
function empty(): SQL;
|
|
@@ -78,3 +82,11 @@ export declare class SQLResponse<TValue = unknown> {
|
|
|
78
82
|
protected $brand: 'SQLResponse';
|
|
79
83
|
constructor(sql: SQL, decoder: DriverValueDecoder<TValue, any>);
|
|
80
84
|
}
|
|
85
|
+
export declare class Placeholder<TName extends string = string, TValue = any> {
|
|
86
|
+
readonly name: TName;
|
|
87
|
+
protected $brand: 'Placeholder';
|
|
88
|
+
protected $type: TValue;
|
|
89
|
+
constructor(name: TName);
|
|
90
|
+
}
|
|
91
|
+
export declare function placeholder<TName extends string>(name: TName): Placeholder<TName>;
|
|
92
|
+
export declare function fillPlaceholders(params: unknown[], values: Record<string, unknown>): unknown[];
|
package/sql/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SQLResponse = exports.sql = exports.param = exports.Param = exports.noopMapper = exports.noopEncoder = exports.noopDecoder = exports.Name = exports.SQL = exports.isSQLWrapper = exports.FakePrimitiveParam = void 0;
|
|
3
|
+
exports.fillPlaceholders = exports.placeholder = exports.Placeholder = exports.SQLResponse = exports.sql = exports.param = exports.Param = exports.noopMapper = exports.noopEncoder = exports.noopDecoder = exports.name = exports.Name = exports.SQL = exports.isSQLWrapper = exports.FakePrimitiveParam = void 0;
|
|
4
4
|
const column_1 = require("../column");
|
|
5
5
|
const table_1 = require("../table");
|
|
6
6
|
/**
|
|
@@ -11,8 +11,9 @@ const table_1 = require("../table");
|
|
|
11
11
|
class FakePrimitiveParam {
|
|
12
12
|
}
|
|
13
13
|
exports.FakePrimitiveParam = FakePrimitiveParam;
|
|
14
|
-
function isSQLWrapper(
|
|
15
|
-
return
|
|
14
|
+
function isSQLWrapper(value) {
|
|
15
|
+
return typeof value === 'object' && value !== null && 'getSQL' in value
|
|
16
|
+
&& typeof value.getSQL === 'function';
|
|
16
17
|
}
|
|
17
18
|
exports.isSQLWrapper = isSQLWrapper;
|
|
18
19
|
class SQL {
|
|
@@ -46,9 +47,7 @@ class SQL {
|
|
|
46
47
|
});
|
|
47
48
|
const sqlString = chunks
|
|
48
49
|
.join('')
|
|
49
|
-
.trim()
|
|
50
|
-
.replace(/\s{2,}/g, ' ')
|
|
51
|
-
.replace(/\n+/g, '');
|
|
50
|
+
.trim();
|
|
52
51
|
return { sql: sqlString, params };
|
|
53
52
|
}
|
|
54
53
|
getSQL() {
|
|
@@ -68,6 +67,13 @@ class Name {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
exports.Name = Name;
|
|
70
|
+
/**
|
|
71
|
+
* Any DB name (table, column, index etc.)
|
|
72
|
+
*/
|
|
73
|
+
function name(value) {
|
|
74
|
+
return new Name(value);
|
|
75
|
+
}
|
|
76
|
+
exports.name = name;
|
|
71
77
|
exports.noopDecoder = {
|
|
72
78
|
mapFromDriverValue: (value) => value,
|
|
73
79
|
};
|
|
@@ -163,4 +169,26 @@ class SQLResponse {
|
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
171
|
exports.SQLResponse = SQLResponse;
|
|
172
|
+
class Placeholder {
|
|
173
|
+
constructor(name) {
|
|
174
|
+
this.name = name;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.Placeholder = Placeholder;
|
|
178
|
+
function placeholder(name) {
|
|
179
|
+
return new Placeholder(name);
|
|
180
|
+
}
|
|
181
|
+
exports.placeholder = placeholder;
|
|
182
|
+
function fillPlaceholders(params, values) {
|
|
183
|
+
return params.map((p) => {
|
|
184
|
+
if (p instanceof Placeholder) {
|
|
185
|
+
if (!(p.name in values)) {
|
|
186
|
+
throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
187
|
+
}
|
|
188
|
+
return values[p.name];
|
|
189
|
+
}
|
|
190
|
+
return p;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
exports.fillPlaceholders = fillPlaceholders;
|
|
166
194
|
//# sourceMappingURL=index.js.map
|
package/sql/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sql/index.ts"],"names":[],"mappings":";;;AAAA,sCAA8C;AAC9C,oCAAiC;AAEjC;;;;GAIG;AACH,MAAa,kBAAkB;CAAG;AAAlC,gDAAkC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sql/index.ts"],"names":[],"mappings":";;;AAAA,sCAA8C;AAC9C,oCAAiC;AAEjC;;;;GAIG;AACH,MAAa,kBAAkB;CAAG;AAAlC,gDAAkC;AAwBlC,SAAgB,YAAY,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,K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kCAEC;AAED,SAAgB,gBAAgB,CAAC,MAAiB,EAAE,MAA+B;IAClF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,IAAI,CAAC,YAAY,WAAW,EAAE;YAC7B,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE;gBACxB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC;aACrE;YACD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SACtB;QAED,OAAO,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACJ,CAAC;AAXD,4CAWC"}
|
package/utils.d.ts
CHANGED
|
@@ -1,5 +1,79 @@
|
|
|
1
|
-
import { Simplify } from 'type-fest';
|
|
2
1
|
import { SelectFieldsOrdered } from './operations';
|
|
3
|
-
export declare function mapResultRow<TResult
|
|
2
|
+
export declare function mapResultRow<TResult>(columns: SelectFieldsOrdered, row: unknown[], joinsNotNullable?: Record<string, boolean>): TResult;
|
|
4
3
|
export declare type OneOrMany<T> = T | T[];
|
|
5
4
|
export declare type Update<T, TUpdate> = Simplify<Omit<T, keyof TUpdate> & TUpdate>;
|
|
5
|
+
/**
|
|
6
|
+
@see Simplify
|
|
7
|
+
*/
|
|
8
|
+
export interface SimplifyOptions {
|
|
9
|
+
/**
|
|
10
|
+
Do the simplification recursively.
|
|
11
|
+
|
|
12
|
+
@default false
|
|
13
|
+
*/
|
|
14
|
+
deep?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare type Flatten<AnyType, Options extends SimplifyOptions = {}> = Options['deep'] extends true ? {
|
|
17
|
+
[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>;
|
|
18
|
+
} : {
|
|
19
|
+
[KeyType in keyof AnyType]: AnyType[KeyType];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
23
|
+
|
|
24
|
+
@example
|
|
25
|
+
```
|
|
26
|
+
import type {Simplify} from 'type-fest';
|
|
27
|
+
|
|
28
|
+
type PositionProps = {
|
|
29
|
+
top: number;
|
|
30
|
+
left: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type SizeProps = {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
39
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
43
|
+
|
|
44
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
45
|
+
|
|
46
|
+
@example
|
|
47
|
+
```
|
|
48
|
+
import type {Simplify} from 'type-fest';
|
|
49
|
+
|
|
50
|
+
interface SomeInterface {
|
|
51
|
+
foo: number;
|
|
52
|
+
bar?: string;
|
|
53
|
+
baz: number | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type SomeType = {
|
|
57
|
+
foo: number;
|
|
58
|
+
bar?: string;
|
|
59
|
+
baz: number | undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
63
|
+
const someType: SomeType = literal;
|
|
64
|
+
const someInterface: SomeInterface = literal;
|
|
65
|
+
|
|
66
|
+
function fn(object: Record<string, unknown>): void {}
|
|
67
|
+
|
|
68
|
+
fn(literal); // Good: literal object type is sealed
|
|
69
|
+
fn(someType); // Good: type is sealed
|
|
70
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
71
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
75
|
+
|
|
76
|
+
@category Object
|
|
77
|
+
*/
|
|
78
|
+
export declare type Simplify<AnyType, Options extends SimplifyOptions = {}> = Flatten<AnyType> extends AnyType ? Flatten<AnyType, Options> : AnyType;
|
|
79
|
+
export {};
|
package/utils.js
CHANGED
|
@@ -4,30 +4,36 @@ exports.mapResultRow = void 0;
|
|
|
4
4
|
const column_1 = require("./column");
|
|
5
5
|
const sql_1 = require("./sql");
|
|
6
6
|
function mapResultRow(columns, row, joinsNotNullable) {
|
|
7
|
-
const result = columns.reduce((
|
|
7
|
+
const result = columns.reduce((result, { path, field }, columnIndex) => {
|
|
8
8
|
let decoder;
|
|
9
|
-
if (
|
|
10
|
-
decoder =
|
|
9
|
+
if (field instanceof column_1.Column) {
|
|
10
|
+
decoder = field;
|
|
11
11
|
}
|
|
12
|
-
else if (
|
|
12
|
+
else if (field instanceof sql_1.SQL) {
|
|
13
13
|
decoder = sql_1.noopDecoder;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
decoder =
|
|
16
|
+
decoder = field.decoder;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
let node = result;
|
|
19
|
+
path.forEach((pathChunk, pathChunkIndex) => {
|
|
20
|
+
if (pathChunkIndex < path.length - 1) {
|
|
21
|
+
if (!(pathChunk in node)) {
|
|
22
|
+
node[pathChunk] = {};
|
|
23
|
+
}
|
|
24
|
+
node = node[pathChunk];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const rawValue = row[columnIndex];
|
|
28
|
+
node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
24
32
|
}, {});
|
|
25
|
-
if (Object.keys(result).length === 1) {
|
|
26
|
-
return Object.values(result)[0];
|
|
27
|
-
}
|
|
28
33
|
if (!joinsNotNullable) {
|
|
29
34
|
return result;
|
|
30
35
|
}
|
|
36
|
+
// If all fields in a table are null, return null for the table
|
|
31
37
|
return Object.fromEntries(Object.entries(result).map(([tableName, tableResult]) => {
|
|
32
38
|
if (!joinsNotNullable[tableName]) {
|
|
33
39
|
const hasNotNull = Object.values(tableResult).some((value) => value !== null);
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAElC,+BAA6D;AAE7D,SAAgB,YAAY,CAC3B,OAA4B,EAC5B,GAAc,EACd,gBAA0C;IAE1C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAC5B,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE;QACxC,IAAI,OAA6C,CAAC;QAClD,IAAI,KAAK,YAAY,eAAM,EAAE;YAC5B,OAAO,GAAG,KAAK,CAAC;SAChB;aAAM,IAAI,KAAK,YAAY,SAAG,EAAE;YAChC,OAAO,GAAG,iBAAW,CAAC;SACtB;aAAM;YACN,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;SACxB;QACD,IAAI,IAAI,GAAG,MAAM,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,cAAc,EAAE,EAAE;YAC1C,IAAI,cAAc,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrC,IAAI,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,EAAE;oBACzB,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;iBACrB;gBACD,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;aACvB;iBAAM;gBACN,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAE,CAAC;gBACnC,IAAI,CAAC,SAAS,CAAC,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;aAClF;QACF,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IACf,CAAC,EACD,EAAE,CACF,CAAC;IAEF,IAAI,CAAC,gBAAgB,EAAE;QACtB,OAAO,MAAiB,CAAC;KACzB;IAED,+DAA+D;IAC/D,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,EAAE;QACvD,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE;YACjC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;YAC9E,IAAI,CAAC,UAAU,EAAE;gBAChB,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;aACzB;SACD;QACD,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACjC,CAAC,CAAC,CACS,CAAC;AACd,CAAC;AAhDD,oCAgDC"}
|
package/branded-types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const brand: unique symbol;
|
|
2
|
-
export declare const value: unique symbol;
|
|
3
|
-
export declare type Brand<T, TName extends string> = T & {
|
|
4
|
-
[brand]: TName;
|
|
5
|
-
[value]: T;
|
|
6
|
-
};
|
|
7
|
-
export declare type AnyBrand = {
|
|
8
|
-
[brand]: any;
|
|
9
|
-
[value]: any;
|
|
10
|
-
};
|
|
11
|
-
export declare type Unwrap<T extends AnyBrand> = T extends {
|
|
12
|
-
[value]: infer TValue;
|
|
13
|
-
} ? TValue : never;
|
|
14
|
-
export declare type TableName<T extends string = string> = Brand<T, 'TableName'>;
|
|
15
|
-
export declare type ColumnData<T = unknown> = Brand<T, 'ColumnData'>;
|
|
16
|
-
export declare type ColumnDriverParam<T = unknown> = Brand<T, 'ColumnDriverParam'>;
|
|
17
|
-
export declare type ColumnNotNull<T extends boolean = boolean> = Brand<T, 'ColumnNotNull'>;
|
|
18
|
-
export declare type ColumnHasDefault<T extends boolean = boolean> = Brand<T, 'ColumnHasDefault'>;
|
package/branded-types.js
DELETED
package/branded-types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"branded-types.js","sourceRoot":"","sources":["../src/branded-types.ts"],"names":[],"mappings":";;;AAAa,QAAA,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACxB,QAAA,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC"}
|
package/readme.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
## DrizzleORM
|
|
2
|
-
DrizzleORM is a TypeScript ORM library with a [drizzle-kit](#migrations) CLI companion for automatic SQL migrations generation.
|
|
3
|
-
It's meant to be a library, not a framework, stay as an opt-in solution all the time at any levels.
|
|
4
|
-
We try to follow SQL-like syntax whenever possible, be strongly typed ground top and fail in compile time, not in runtime.
|
|
5
|
-
We implemented best in class `joins` and second to none `migrations generation`.
|
|
6
|
-
Library has almost zero dependencies and being battle tested on production projects by multiple teams 🚀
|
|
7
|
-
|
|
8
|
-
| database | support | |
|
|
9
|
-
|:-- | :---: | :-- |
|
|
10
|
-
| PostgreSQL | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-pg)|
|
|
11
|
-
| MySQL | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-mysql)| |
|
|
12
|
-
| SQLite | ⏳ | |
|
|
13
|
-
| DynamoDB | ⏳ | |
|
|
14
|
-
| MS SQL | ⏳ | |
|
|
15
|
-
| CockroachDB | ⏳ | |
|
|
16
|
-
|
|
17
|
-
### Installation
|
|
18
|
-
```bash
|
|
19
|
-
// postgresql
|
|
20
|
-
npm install drizzle-orm drizzle-orm-pg
|
|
21
|
-
npm install -D drizzle-kit
|
|
22
|
-
```
|