drizzle-orm 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/connection.d.ts +0 -13
- package/connection.js +1 -46
- package/connection.js.map +1 -1
- package/migrator.d.ts +13 -0
- package/migrator.js +52 -0
- package/migrator.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>Drizzle ORM</h1>
|
|
3
|
+
<a href="https://www.npmjs.com/package/drizzle-orm"><img alt="" src="https://img.shields.io/npm/v/drizzle-orm"></a>
|
|
4
|
+
<img alt="" src="https://img.shields.io/npm/dw/drizzle-orm">
|
|
5
|
+
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/drizzle-orm">
|
|
6
|
+
<img alt="Discord" src="https://img.shields.io/discord/1043890932593987624">
|
|
7
|
+
<a href="https://github.com/drizzle-team/drizzle-orm/blob/main/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/drizzle-team/drizzle-orm"></a>
|
|
8
|
+
<hr />
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
DrizzleORM is a TypeScript ORM library with a [drizzle-kit](#migrations) CLI companion for automatic SQL migrations generation.
|
|
12
|
+
It's meant to be a library, not a framework, stay as an opt-in solution all the time at any levels.
|
|
4
13
|
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`.
|
|
14
|
+
We implemented best in class `joins` and second to none `migrations generation`.
|
|
6
15
|
Library has almost zero dependencies and being battle tested on production projects by multiple teams 🚀
|
|
7
16
|
|
|
8
17
|
| database | support | |
|
|
9
18
|
|:-- | :---: | :-- |
|
|
10
19
|
| PostgreSQL | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-pg)|
|
|
11
|
-
| MySQL | ⏳ | |
|
|
12
|
-
| SQLite | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-sqlite)|
|
|
20
|
+
| MySQL | ⏳ | |
|
|
21
|
+
| SQLite | ✅ |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-sqlite)|
|
|
13
22
|
| DynamoDB | ⏳ | |
|
|
14
23
|
| MS SQL | ⏳ | |
|
|
15
24
|
| CockroachDB | ⏳ | |
|
|
16
25
|
|
|
17
26
|
### Installation
|
|
27
|
+
|
|
18
28
|
```bash
|
|
19
29
|
// postgresql
|
|
20
30
|
npm install drizzle-orm drizzle-orm-pg
|
package/connection.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export declare type MigrationMeta = {
|
|
2
|
-
sql: string;
|
|
3
|
-
folderMillis: number;
|
|
4
|
-
hash: string;
|
|
5
|
-
};
|
|
6
1
|
export interface Logger {
|
|
7
2
|
logQuery(query: string, params: unknown[]): void;
|
|
8
3
|
}
|
|
@@ -22,11 +17,3 @@ export declare class DefaultLogger implements Logger {
|
|
|
22
17
|
export declare class NoopLogger implements Logger {
|
|
23
18
|
logQuery(): void;
|
|
24
19
|
}
|
|
25
|
-
export interface KitConfig {
|
|
26
|
-
out: string;
|
|
27
|
-
schema: string;
|
|
28
|
-
}
|
|
29
|
-
export interface MigrationConfig {
|
|
30
|
-
migrationsFolder: string;
|
|
31
|
-
}
|
|
32
|
-
export declare function readMigrationFiles(config: string | MigrationConfig): MigrationMeta[];
|
package/connection.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NoopLogger = exports.DefaultLogger = exports.ConsoleLogWriter = void 0;
|
|
4
4
|
class ConsoleLogWriter {
|
|
5
5
|
write(message) {
|
|
6
6
|
console.log(message);
|
|
@@ -29,49 +29,4 @@ class NoopLogger {
|
|
|
29
29
|
logQuery() { }
|
|
30
30
|
}
|
|
31
31
|
exports.NoopLogger = NoopLogger;
|
|
32
|
-
function readMigrationFiles(config) {
|
|
33
|
-
const fs = require('fs');
|
|
34
|
-
const crypto = require('crypto');
|
|
35
|
-
const path = require('path');
|
|
36
|
-
let migrationFolderTo;
|
|
37
|
-
if (typeof config === 'string') {
|
|
38
|
-
const configAsString = fs.readFileSync(path.resolve('.', config), 'utf8');
|
|
39
|
-
const jsonConfig = JSON.parse(configAsString);
|
|
40
|
-
migrationFolderTo = jsonConfig.out;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
migrationFolderTo = config.migrationsFolder;
|
|
44
|
-
}
|
|
45
|
-
if (!migrationFolderTo) {
|
|
46
|
-
throw Error('no migration folder defined');
|
|
47
|
-
}
|
|
48
|
-
const files = fs.readdirSync(migrationFolderTo);
|
|
49
|
-
const migrationQueries = [];
|
|
50
|
-
for (const migrationFolder of files) {
|
|
51
|
-
if (migrationFolder === '.DS_Store') {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const migrationFiles = fs.readdirSync(`${migrationFolderTo}/${migrationFolder}`);
|
|
55
|
-
const migrationFile = migrationFiles.filter((file) => file === 'migration.sql')[0];
|
|
56
|
-
const query = fs
|
|
57
|
-
.readFileSync(`${migrationFolderTo}/${migrationFolder}/${migrationFile}`)
|
|
58
|
-
.toString();
|
|
59
|
-
const year = Number(migrationFolder.slice(0, 4));
|
|
60
|
-
// second param for Date() is month index, that started from 0, so we need
|
|
61
|
-
// to decrement a value for month
|
|
62
|
-
const month = Number(migrationFolder.slice(4, 6)) - 1;
|
|
63
|
-
const day = Number(migrationFolder.slice(6, 8));
|
|
64
|
-
const hour = Number(migrationFolder.slice(8, 10));
|
|
65
|
-
const min = Number(migrationFolder.slice(10, 12));
|
|
66
|
-
const sec = Number(migrationFolder.slice(12, 14));
|
|
67
|
-
const folderAsMillis = Date.UTC(year, month, day, hour, min, sec);
|
|
68
|
-
migrationQueries.push({
|
|
69
|
-
sql: query,
|
|
70
|
-
folderMillis: folderAsMillis,
|
|
71
|
-
hash: crypto.createHash('sha256').update(query).digest('hex'),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return migrationQueries;
|
|
75
|
-
}
|
|
76
|
-
exports.readMigrationFiles = readMigrationFiles;
|
|
77
32
|
//# sourceMappingURL=connection.js.map
|
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":";;;AAQA,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,OAAO,CAAC,EAAE;gBACX,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;aACjB;QACF,CAAC,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAClG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,GAAG,SAAS,EAAE,CAAC,CAAC;IAClD,CAAC;CACD;AAlBD,sCAkBC;AAED,MAAa,UAAU;IACtB,QAAQ,KAAU,CAAC;CACnB;AAFD,gCAEC"}
|
package/migrator.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface KitConfig {
|
|
2
|
+
out: string;
|
|
3
|
+
schema: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MigrationConfig {
|
|
6
|
+
migrationsFolder: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MigrationMeta {
|
|
9
|
+
sql: string;
|
|
10
|
+
folderMillis: number;
|
|
11
|
+
hash: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function readMigrationFiles(config: string | MigrationConfig): MigrationMeta[];
|
package/migrator.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readMigrationFiles = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function readMigrationFiles(config) {
|
|
11
|
+
let migrationFolderTo;
|
|
12
|
+
if (typeof config === 'string') {
|
|
13
|
+
const configAsString = fs_1.default.readFileSync(path_1.default.resolve('.', config), 'utf8');
|
|
14
|
+
const jsonConfig = JSON.parse(configAsString);
|
|
15
|
+
migrationFolderTo = jsonConfig.out;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
migrationFolderTo = config.migrationsFolder;
|
|
19
|
+
}
|
|
20
|
+
if (!migrationFolderTo) {
|
|
21
|
+
throw Error('no migration folder defined');
|
|
22
|
+
}
|
|
23
|
+
const files = fs_1.default.readdirSync(migrationFolderTo);
|
|
24
|
+
const migrationQueries = [];
|
|
25
|
+
for (const migrationFolder of files) {
|
|
26
|
+
if (migrationFolder === '.DS_Store') {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const migrationFiles = fs_1.default.readdirSync(`${migrationFolderTo}/${migrationFolder}`);
|
|
30
|
+
const migrationFile = migrationFiles.filter((file) => file === 'migration.sql')[0];
|
|
31
|
+
const query = fs_1.default
|
|
32
|
+
.readFileSync(`${migrationFolderTo}/${migrationFolder}/${migrationFile}`)
|
|
33
|
+
.toString();
|
|
34
|
+
const year = Number(migrationFolder.slice(0, 4));
|
|
35
|
+
// second param for Date() is month index, that started from 0, so we need
|
|
36
|
+
// to decrement a value for month
|
|
37
|
+
const month = Number(migrationFolder.slice(4, 6)) - 1;
|
|
38
|
+
const day = Number(migrationFolder.slice(6, 8));
|
|
39
|
+
const hour = Number(migrationFolder.slice(8, 10));
|
|
40
|
+
const min = Number(migrationFolder.slice(10, 12));
|
|
41
|
+
const sec = Number(migrationFolder.slice(12, 14));
|
|
42
|
+
const folderAsMillis = Date.UTC(year, month, day, hour, min, sec);
|
|
43
|
+
migrationQueries.push({
|
|
44
|
+
sql: query,
|
|
45
|
+
folderMillis: folderAsMillis,
|
|
46
|
+
hash: crypto_1.default.createHash('sha256').update(query).digest('hex'),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return migrationQueries;
|
|
50
|
+
}
|
|
51
|
+
exports.readMigrationFiles = readMigrationFiles;
|
|
52
|
+
//# sourceMappingURL=migrator.js.map
|
package/migrator.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.js","sourceRoot":"","sources":["../src/migrator.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,4CAAoB;AACpB,gDAAwB;AAiBxB,SAAgB,kBAAkB,CAAC,MAAgC;IAClE,IAAI,iBAAqC,CAAC;IAC1C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC/B,MAAM,cAAc,GAAG,YAAE,CAAC,Y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