@effect/sql-sqlite-wasm 0.0.0-snapshot-189d4cae80e186661241002ad9d729628096520f
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/Client/package.json +6 -0
- package/LICENSE +21 -0
- package/Migrator/package.json +6 -0
- package/README.md +5 -0
- package/dist/cjs/Client.js +148 -0
- package/dist/cjs/Client.js.map +1 -0
- package/dist/cjs/Migrator.js +76 -0
- package/dist/cjs/Migrator.js.map +1 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/dts/Client.d.ts +60 -0
- package/dist/dts/Client.d.ts.map +1 -0
- package/dist/dts/Migrator.d.ts +23 -0
- package/dist/dts/Migrator.d.ts.map +1 -0
- package/dist/dts/index.d.ts +28 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/esm/Client.js +108 -0
- package/dist/esm/Client.js.map +1 -0
- package/dist/esm/Migrator.js +29 -0
- package/dist/esm/Migrator.js.map +1 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +4 -0
- package/package.json +58 -0
- package/sqlite-wasm.d/package.json +6 -0
- package/src/Client.ts +191 -0
- package/src/Migrator.ts +44 -0
- package/src/index.ts +33 -0
- package/src/sqlite-wasm.d.ts +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present The Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.makeCompiler = exports.make = exports.layer = exports.SqliteClient = void 0;
|
|
7
|
+
var Client = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Client"));
|
|
8
|
+
var _Error = /*#__PURE__*/require("@effect/sql/Error");
|
|
9
|
+
var Statement = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Statement"));
|
|
10
|
+
var _sqliteWasm = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("@sqlite.org/sqlite-wasm"));
|
|
11
|
+
var Config = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Config"));
|
|
12
|
+
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Context"));
|
|
13
|
+
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
14
|
+
var _Function = /*#__PURE__*/require("effect/Function");
|
|
15
|
+
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
16
|
+
var Scope = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Scope"));
|
|
17
|
+
function _interopRequireDefault(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function _getRequireWildcardCache(e) {
|
|
23
|
+
if ("function" != typeof WeakMap) return null;
|
|
24
|
+
var r = new WeakMap(),
|
|
25
|
+
t = new WeakMap();
|
|
26
|
+
return (_getRequireWildcardCache = function (e) {
|
|
27
|
+
return e ? t : r;
|
|
28
|
+
})(e);
|
|
29
|
+
}
|
|
30
|
+
function _interopRequireWildcard(e, r) {
|
|
31
|
+
if (!r && e && e.__esModule) return e;
|
|
32
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return {
|
|
33
|
+
default: e
|
|
34
|
+
};
|
|
35
|
+
var t = _getRequireWildcardCache(r);
|
|
36
|
+
if (t && t.has(e)) return t.get(e);
|
|
37
|
+
var n = {
|
|
38
|
+
__proto__: null
|
|
39
|
+
},
|
|
40
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
|
+
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
42
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
43
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
44
|
+
}
|
|
45
|
+
return n.default = e, t && t.set(e, n), n;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @category tags
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*/
|
|
55
|
+
const SqliteClient = exports.SqliteClient = /*#__PURE__*/Context.GenericTag("@effect/sql-sqlite-wasm/SqliteClient");
|
|
56
|
+
const initEffect = /*#__PURE__*/Effect.runSync( /*#__PURE__*/Effect.cached( /*#__PURE__*/Effect.promise(() => (0, _sqliteWasm.default)())));
|
|
57
|
+
/**
|
|
58
|
+
* @category constructor
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
*/
|
|
61
|
+
const make = options => Effect.gen(function* (_) {
|
|
62
|
+
const compiler = makeCompiler(options.transformQueryNames);
|
|
63
|
+
const transformRows = Client.defaultTransforms(options.transformResultNames).array;
|
|
64
|
+
const makeConnection = Effect.gen(function* (_) {
|
|
65
|
+
const sqlite3 = yield* _(initEffect);
|
|
66
|
+
let db;
|
|
67
|
+
if (options.mode === "opfs") {
|
|
68
|
+
if (!sqlite3.oo1.OpfsDb) {
|
|
69
|
+
yield* _(Effect.dieMessage("opfs mode not available"));
|
|
70
|
+
}
|
|
71
|
+
db = new sqlite3.oo1.OpfsDb(options.dbName, options.openMode ?? "c");
|
|
72
|
+
} else {
|
|
73
|
+
db = new sqlite3.oo1.DB(options.dbName, options.openMode);
|
|
74
|
+
}
|
|
75
|
+
yield* _(Effect.addFinalizer(() => Effect.sync(() => db.close())));
|
|
76
|
+
const run = (sql, params = [], rowMode = "object") => Effect.try({
|
|
77
|
+
try: () => {
|
|
78
|
+
const results = [];
|
|
79
|
+
db.exec({
|
|
80
|
+
sql,
|
|
81
|
+
bind: params.length ? params : undefined,
|
|
82
|
+
rowMode,
|
|
83
|
+
resultRows: results
|
|
84
|
+
});
|
|
85
|
+
return results;
|
|
86
|
+
},
|
|
87
|
+
catch: error => new _Error.SqlError({
|
|
88
|
+
error
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
const runTransform = options.transformResultNames ? (sql, params) => Effect.map(run(sql, params), transformRows) : run;
|
|
92
|
+
return (0, _Function.identity)({
|
|
93
|
+
execute(sql, params) {
|
|
94
|
+
return runTransform(sql, params);
|
|
95
|
+
},
|
|
96
|
+
executeValues(sql, params) {
|
|
97
|
+
return run(sql, params, "array");
|
|
98
|
+
},
|
|
99
|
+
executeWithoutTransform(sql, params) {
|
|
100
|
+
return run(sql, params);
|
|
101
|
+
},
|
|
102
|
+
executeRaw(sql, params) {
|
|
103
|
+
return runTransform(sql, params);
|
|
104
|
+
},
|
|
105
|
+
executeStream() {
|
|
106
|
+
return Effect.dieMessage("executeStream not implemented");
|
|
107
|
+
},
|
|
108
|
+
export: Effect.try({
|
|
109
|
+
try: () => sqlite3.capi.sqlite3_js_db_export(db.pointer),
|
|
110
|
+
catch: error => new _Error.SqlError({
|
|
111
|
+
error
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
const semaphore = yield* _(Effect.makeSemaphore(1));
|
|
117
|
+
const connection = yield* _(makeConnection);
|
|
118
|
+
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
119
|
+
const transactionAcquirer = Effect.uninterruptibleMask(restore => Effect.as(Effect.zipRight(restore(semaphore.take(1)), Effect.tap(Effect.scope, scope => Scope.addFinalizer(scope, semaphore.release(1)))), connection));
|
|
120
|
+
return Object.assign(Client.make({
|
|
121
|
+
acquirer,
|
|
122
|
+
compiler,
|
|
123
|
+
transactionAcquirer
|
|
124
|
+
}), {
|
|
125
|
+
config: options,
|
|
126
|
+
export: Effect.flatMap(acquirer, _ => _.export)
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* @category layers
|
|
131
|
+
* @since 1.0.0
|
|
132
|
+
*/
|
|
133
|
+
exports.make = make;
|
|
134
|
+
const layer = config => Layer.scoped(SqliteClient, Effect.flatMap(Config.unwrap(config), make));
|
|
135
|
+
exports.layer = layer;
|
|
136
|
+
const escape = /*#__PURE__*/Statement.defaultEscape("\"");
|
|
137
|
+
/**
|
|
138
|
+
* @category compiler
|
|
139
|
+
* @since 1.0.0
|
|
140
|
+
*/
|
|
141
|
+
const makeCompiler = transform => Statement.makeCompiler({
|
|
142
|
+
placeholder: _ => `?`,
|
|
143
|
+
onIdentifier: transform ? _ => escape(transform(_)) : escape,
|
|
144
|
+
onRecordUpdate: () => ["", []],
|
|
145
|
+
onCustom: () => ["", []]
|
|
146
|
+
});
|
|
147
|
+
exports.makeCompiler = makeCompiler;
|
|
148
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","names":["Client","_interopRequireWildcard","require","_Error","Statement","_sqliteWasm","_interopRequireDefault","Config","Context","Effect","_Function","Layer","Scope","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","SqliteClient","exports","GenericTag","initEffect","runSync","cached","promise","make","options","gen","_","compiler","makeCompiler","transformQueryNames","transformRows","defaultTransforms","transformResultNames","array","makeConnection","sqlite3","db","mode","oo1","OpfsDb","dieMessage","dbName","openMode","DB","addFinalizer","sync","close","run","sql","params","rowMode","try","results","exec","bind","length","undefined","resultRows","catch","error","SqlError","runTransform","map","identity","execute","executeValues","executeWithoutTransform","executeRaw","executeStream","export","capi","sqlite3_js_db_export","pointer","semaphore","makeSemaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","as","zipRight","take","tap","scope","release","assign","config","flatMap","layer","scoped","unwrap","escape","defaultEscape","transform","placeholder","onIdentifier","onRecordUpdate","onCustom"],"sources":["../../src/Client.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,MAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAEA,IAAAC,MAAA,gBAAAD,OAAA;AACA,IAAAE,SAAA,gBAAAH,uBAAA,eAAAC,OAAA;AAEA,IAAAG,WAAA,gBAAAC,sBAAA,eAAAJ,OAAA;AACA,IAAAK,MAAA,gBAAAN,uBAAA,eAAAC,OAAA;AAEA,IAAAM,OAAA,gBAAAP,uBAAA,eAAAC,OAAA;AACA,IAAAO,MAAA,gBAAAR,uBAAA,eAAAC,OAAA;AACA,IAAAQ,SAAA,gBAAAR,O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CAAC,EACF;IACEU,MAAM,EAAEjE,OAAO;IACf6C,MAAM,EAAE9E,MAAM,CAACmG,OAAO,CAACd,QAAQ,EAAGlD,CAAC,IAAKA,CAAC,CAAC2C,MAAM;GACjD,CACF;AACH,CAAC,CAAC;AAEJ;;;;AAAApD,OAAA,CAAAM,IAAA,GAAAA,IAAA;AAIO,MAAMoE,KAAK,GAChBF,MAA8C,IAE9ChG,KAAK,CAACmG,MAAM,CACV5E,YAAY,EACZzB,MAAM,CAACmG,OAAO,CAACrG,MAAM,CAACwG,MAAM,CAACJ,MAAM,CAAC,EAAElE,IAAI,CAAC,CAC5C;AAAAN,OAAA,CAAA0E,KAAA,GAAAA,KAAA;AAEH,MAAMG,MAAM,gBAAG5G,SAAS,CAAC6G,aAAa,CAAC,IAAI,CAAC;AAE5C;;;;AAIO,MAAMnE,YAAY,GAAIoE,SAAiC,IAC5D9G,SAAS,CAAC0C,YAAY,CAAC;EACrBqE,WAAW,EAAGvE,CAAC,IAAK,GAAG;EACvBwE,YAAY,EAAEF,SAAS,GAAItE,CAAC,IAAKoE,MAAM,CAACE,SAAS,CAACtE,CAAC,CAAC,CAAC,GAAGoE,MAAM;EAC9DK,cAAc,EAAEA,CAAA,KAAM,CAAC,EAAE,EAAE,EAAE,CAAC;EAC9BC,QAAQ,EAAEA,CAAA,KAAM,CAAC,EAAE,EAAE,EAAE;CACxB,CAAC;AAAAnF,OAAA,CAAAW,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
run: true,
|
|
8
|
+
makeLayer: true
|
|
9
|
+
};
|
|
10
|
+
exports.run = exports.makeLayer = void 0;
|
|
11
|
+
var Migrator = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Migrator"));
|
|
12
|
+
Object.keys(Migrator).forEach(function (key) {
|
|
13
|
+
if (key === "default" || key === "__esModule") return;
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
15
|
+
if (key in exports && exports[key] === Migrator[key]) return;
|
|
16
|
+
Object.defineProperty(exports, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return Migrator[key];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
24
|
+
var Client = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Client.js"));
|
|
25
|
+
function _getRequireWildcardCache(e) {
|
|
26
|
+
if ("function" != typeof WeakMap) return null;
|
|
27
|
+
var r = new WeakMap(),
|
|
28
|
+
t = new WeakMap();
|
|
29
|
+
return (_getRequireWildcardCache = function (e) {
|
|
30
|
+
return e ? t : r;
|
|
31
|
+
})(e);
|
|
32
|
+
}
|
|
33
|
+
function _interopRequireWildcard(e, r) {
|
|
34
|
+
if (!r && e && e.__esModule) return e;
|
|
35
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return {
|
|
36
|
+
default: e
|
|
37
|
+
};
|
|
38
|
+
var t = _getRequireWildcardCache(r);
|
|
39
|
+
if (t && t.has(e)) return t.get(e);
|
|
40
|
+
var n = {
|
|
41
|
+
__proto__: null
|
|
42
|
+
},
|
|
43
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
44
|
+
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
45
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
46
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
47
|
+
}
|
|
48
|
+
return n.default = e, t && t.set(e, n), n;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @since 1.0.0
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @category constructor
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
58
|
+
const run = exports.run = /*#__PURE__*/Migrator.make({
|
|
59
|
+
getClient: Client.SqliteClient,
|
|
60
|
+
ensureTable(sql, table) {
|
|
61
|
+
return sql`
|
|
62
|
+
CREATE TABLE IF NOT EXISTS ${sql(table)} (
|
|
63
|
+
migration_id integer PRIMARY KEY NOT NULL,
|
|
64
|
+
created_at datetime NOT NULL DEFAULT current_timestamp,
|
|
65
|
+
name VARCHAR(255) NOT NULL
|
|
66
|
+
)
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* @category constructor
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
*/
|
|
74
|
+
const makeLayer = options => Layer.effectDiscard(run(options));
|
|
75
|
+
exports.makeLayer = makeLayer;
|
|
76
|
+
//# sourceMappingURL=Migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migrator.js","names":["Migrator","_interopRequireWildcard","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Layer","Client","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","run","make","getClient","SqliteClient","ensureTable","sql","table","makeLayer","options","effectDiscard"],"sources":["../../src/Migrator.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;AAIA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAQAC,MAAA,CAAAC,IAAA,CAAAJ,QAAA,EAAAK,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAA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AAA,EAAAI,CAAA,EAAAC,CAAA,IAAAL,CAAA,CAAAI,CAAA,IAAAX,CAAA,CAAAW,CAAA;EAAA;EAAA,OAAAJ,CAAA,CAAAF,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAU,GAAA,CAAAb,CAAA,EAAAO,CAAA,GAAAA,CAAA;AAAA;AAErC;;;;AAKA;;;;AAIO,MAAMO,GAAG,GAAArB,OAAA,CAAAqB,GAAA,gBAMZhC,QAAQ,CAACiC,IAAI,CAAC;EAChBC,SAAS,EAAElB,MAAM,CAACmB,YAAY;EAC9BC,WAAWA,CAACC,GAAG,EAAEC,KAAK;IACpB,OAAOD,GAAG;mCACqBA,GAAG,CAACC,KAAK,CAAC;;;;;KAKxC;EACH;CACD,CAAC;AAEF;;;;AAIO,MAAMC,SAAS,GACpBC,OAAiC,IAC+CzB,KAAK,CAAC0B,aAAa,CAACT,GAAG,CAACQ,OAAO,CAAC,CAAC;AAAA7B,OAAA,CAAA4B,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.statement = exports.schema = exports.resolver = exports.migrator = exports.error = exports.client = void 0;
|
|
7
|
+
var _client = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Client.js"));
|
|
8
|
+
exports.client = _client;
|
|
9
|
+
var _error = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Error"));
|
|
10
|
+
exports.error = _error;
|
|
11
|
+
var _migrator = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Migrator.js"));
|
|
12
|
+
exports.migrator = _migrator;
|
|
13
|
+
var _resolver = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Resolver"));
|
|
14
|
+
exports.resolver = _resolver;
|
|
15
|
+
var _schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Schema"));
|
|
16
|
+
exports.schema = _schema;
|
|
17
|
+
var _statement = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/sql/Statement"));
|
|
18
|
+
exports.statement = _statement;
|
|
19
|
+
function _getRequireWildcardCache(e) {
|
|
20
|
+
if ("function" != typeof WeakMap) return null;
|
|
21
|
+
var r = new WeakMap(),
|
|
22
|
+
t = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function (e) {
|
|
24
|
+
return e ? t : r;
|
|
25
|
+
})(e);
|
|
26
|
+
}
|
|
27
|
+
function _interopRequireWildcard(e, r) {
|
|
28
|
+
if (!r && e && e.__esModule) return e;
|
|
29
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return {
|
|
30
|
+
default: e
|
|
31
|
+
};
|
|
32
|
+
var t = _getRequireWildcardCache(r);
|
|
33
|
+
if (t && t.has(e)) return t.get(e);
|
|
34
|
+
var n = {
|
|
35
|
+
__proto__: null
|
|
36
|
+
},
|
|
37
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
+
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
39
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
40
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
41
|
+
}
|
|
42
|
+
return n.default = e, t && t.set(e, n), n;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/// <reference types="@effect/sql-sqlite-wasm/sqlite-wasm" />
|
|
2
|
+
/**
|
|
3
|
+
* @since 1.0.0
|
|
4
|
+
*/
|
|
5
|
+
import * as Client from "@effect/sql/Client";
|
|
6
|
+
import { SqlError } from "@effect/sql/Error";
|
|
7
|
+
import * as Statement from "@effect/sql/Statement";
|
|
8
|
+
import type { OpenMode } from "@sqlite.org/sqlite-wasm";
|
|
9
|
+
import * as Config from "effect/Config";
|
|
10
|
+
import type { ConfigError } from "effect/ConfigError";
|
|
11
|
+
import * as Context from "effect/Context";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as Layer from "effect/Layer";
|
|
14
|
+
import * as Scope from "effect/Scope";
|
|
15
|
+
/**
|
|
16
|
+
* @category models
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
export interface SqliteClient extends Client.Client {
|
|
20
|
+
readonly config: SqliteClientConfig;
|
|
21
|
+
readonly export: Effect.Effect<Uint8Array, SqlError>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @category tags
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
export declare const SqliteClient: Context.Tag<SqliteClient, SqliteClient>;
|
|
28
|
+
/**
|
|
29
|
+
* @category models
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
export type SqliteClientConfig = {
|
|
33
|
+
readonly mode?: "vfs";
|
|
34
|
+
readonly dbName?: string;
|
|
35
|
+
readonly openMode?: OpenMode;
|
|
36
|
+
readonly transformResultNames?: (str: string) => string;
|
|
37
|
+
readonly transformQueryNames?: (str: string) => string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly mode: "opfs";
|
|
40
|
+
readonly dbName: string;
|
|
41
|
+
readonly openMode?: OpenMode;
|
|
42
|
+
readonly transformResultNames?: (str: string) => string;
|
|
43
|
+
readonly transformQueryNames?: (str: string) => string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @category constructor
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
export declare const make: (options: SqliteClientConfig) => Effect.Effect<SqliteClient, never, Scope.Scope>;
|
|
50
|
+
/**
|
|
51
|
+
* @category layers
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
*/
|
|
54
|
+
export declare const layer: (config: Config.Config.Wrap<SqliteClientConfig>) => Layer.Layer<SqliteClient, ConfigError>;
|
|
55
|
+
/**
|
|
56
|
+
* @category compiler
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
59
|
+
export declare const makeCompiler: (transform?: ((_: string) => string) | undefined) => Statement.Compiler;
|
|
60
|
+
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/Client.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAM,QAAQ,EAAW,MAAM,yBAAyB,CAAA;AAEpE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM;IACjD,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;CACrD;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAEhE,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IACA,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAC5B,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACvD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CACvD,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAC5B,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACvD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CACvD,CAAA;AAUH;;;GAGG;AACH,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,aAAa,CAAC,YAAY,EAAE,KAAK,EAAE,WAAW,CAgG7C,CAAA;AAEJ;;;GAGG;AACH,eAAO,MAAM,KAAK,WACR,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAC7C,WAAW,CAAC,YAAY,EAAE,WAAW,CAIrC,CAAA;AAIH;;;GAGG;AACH,eAAO,MAAM,YAAY,oBAAoB,MAAM,KAAK,MAAM,oCAM1D,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { SqlError } from "@effect/sql/Error";
|
|
5
|
+
import * as Migrator from "@effect/sql/Migrator";
|
|
6
|
+
import type * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Client from "./Client.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
export * from "@effect/sql/Migrator";
|
|
13
|
+
/**
|
|
14
|
+
* @category constructor
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
export declare const run: <R>(options: Migrator.MigratorOptions<R>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, SqlError | Migrator.MigrationError, Client.SqliteClient | R>;
|
|
18
|
+
/**
|
|
19
|
+
* @category constructor
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export declare const makeLayer: (options: Migrator.MigratorOptions) => Layer.Layer<never, SqlError | Migrator.MigrationError, Client.SqliteClient>;
|
|
23
|
+
//# sourceMappingURL=Migrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migrator.d.ts","sourceRoot":"","sources":["../../src/Migrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;GAEG;AACH,cAAc,sBAAsB,CAAA;AAEpC;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,EAClB,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACjC,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAClC,MAAM,CAAC,YAAY,GAAG,CAAC,CAYvB,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,YACX,SAAS,eAAe,KAChC,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,cAAc,EAAE,OAAO,YAAY,CAAsC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export * as client from "./Client.js";
|
|
8
|
+
/**
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
export * as error from "@effect/sql/Error";
|
|
12
|
+
/**
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export * as migrator from "./Migrator.js";
|
|
16
|
+
/**
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
export * as resolver from "@effect/sql/Resolver";
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
export * as schema from "@effect/sql/Schema";
|
|
24
|
+
/**
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
export * as statement from "@effect/sql/Statement";
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAE1C;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAEhD;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAE5C;;GAEG;AACH,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Client from "@effect/sql/Client";
|
|
5
|
+
import { SqlError } from "@effect/sql/Error";
|
|
6
|
+
import * as Statement from "@effect/sql/Statement";
|
|
7
|
+
import sqliteInit from "@sqlite.org/sqlite-wasm";
|
|
8
|
+
import * as Config from "effect/Config";
|
|
9
|
+
import * as Context from "effect/Context";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import { identity } from "effect/Function";
|
|
12
|
+
import * as Layer from "effect/Layer";
|
|
13
|
+
import * as Scope from "effect/Scope";
|
|
14
|
+
/**
|
|
15
|
+
* @category tags
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
export const SqliteClient = /*#__PURE__*/Context.GenericTag("@effect/sql-sqlite-wasm/SqliteClient");
|
|
19
|
+
const initEffect = /*#__PURE__*/Effect.runSync( /*#__PURE__*/Effect.cached( /*#__PURE__*/Effect.promise(() => sqliteInit())));
|
|
20
|
+
/**
|
|
21
|
+
* @category constructor
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export const make = options => Effect.gen(function* (_) {
|
|
25
|
+
const compiler = makeCompiler(options.transformQueryNames);
|
|
26
|
+
const transformRows = Client.defaultTransforms(options.transformResultNames).array;
|
|
27
|
+
const makeConnection = Effect.gen(function* (_) {
|
|
28
|
+
const sqlite3 = yield* _(initEffect);
|
|
29
|
+
let db;
|
|
30
|
+
if (options.mode === "opfs") {
|
|
31
|
+
if (!sqlite3.oo1.OpfsDb) {
|
|
32
|
+
yield* _(Effect.dieMessage("opfs mode not available"));
|
|
33
|
+
}
|
|
34
|
+
db = new sqlite3.oo1.OpfsDb(options.dbName, options.openMode ?? "c");
|
|
35
|
+
} else {
|
|
36
|
+
db = new sqlite3.oo1.DB(options.dbName, options.openMode);
|
|
37
|
+
}
|
|
38
|
+
yield* _(Effect.addFinalizer(() => Effect.sync(() => db.close())));
|
|
39
|
+
const run = (sql, params = [], rowMode = "object") => Effect.try({
|
|
40
|
+
try: () => {
|
|
41
|
+
const results = [];
|
|
42
|
+
db.exec({
|
|
43
|
+
sql,
|
|
44
|
+
bind: params.length ? params : undefined,
|
|
45
|
+
rowMode,
|
|
46
|
+
resultRows: results
|
|
47
|
+
});
|
|
48
|
+
return results;
|
|
49
|
+
},
|
|
50
|
+
catch: error => new SqlError({
|
|
51
|
+
error
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
const runTransform = options.transformResultNames ? (sql, params) => Effect.map(run(sql, params), transformRows) : run;
|
|
55
|
+
return identity({
|
|
56
|
+
execute(sql, params) {
|
|
57
|
+
return runTransform(sql, params);
|
|
58
|
+
},
|
|
59
|
+
executeValues(sql, params) {
|
|
60
|
+
return run(sql, params, "array");
|
|
61
|
+
},
|
|
62
|
+
executeWithoutTransform(sql, params) {
|
|
63
|
+
return run(sql, params);
|
|
64
|
+
},
|
|
65
|
+
executeRaw(sql, params) {
|
|
66
|
+
return runTransform(sql, params);
|
|
67
|
+
},
|
|
68
|
+
executeStream() {
|
|
69
|
+
return Effect.dieMessage("executeStream not implemented");
|
|
70
|
+
},
|
|
71
|
+
export: Effect.try({
|
|
72
|
+
try: () => sqlite3.capi.sqlite3_js_db_export(db.pointer),
|
|
73
|
+
catch: error => new SqlError({
|
|
74
|
+
error
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
const semaphore = yield* _(Effect.makeSemaphore(1));
|
|
80
|
+
const connection = yield* _(makeConnection);
|
|
81
|
+
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
82
|
+
const transactionAcquirer = Effect.uninterruptibleMask(restore => Effect.as(Effect.zipRight(restore(semaphore.take(1)), Effect.tap(Effect.scope, scope => Scope.addFinalizer(scope, semaphore.release(1)))), connection));
|
|
83
|
+
return Object.assign(Client.make({
|
|
84
|
+
acquirer,
|
|
85
|
+
compiler,
|
|
86
|
+
transactionAcquirer
|
|
87
|
+
}), {
|
|
88
|
+
config: options,
|
|
89
|
+
export: Effect.flatMap(acquirer, _ => _.export)
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* @category layers
|
|
94
|
+
* @since 1.0.0
|
|
95
|
+
*/
|
|
96
|
+
export const layer = config => Layer.scoped(SqliteClient, Effect.flatMap(Config.unwrap(config), make));
|
|
97
|
+
const escape = /*#__PURE__*/Statement.defaultEscape("\"");
|
|
98
|
+
/**
|
|
99
|
+
* @category compiler
|
|
100
|
+
* @since 1.0.0
|
|
101
|
+
*/
|
|
102
|
+
export const makeCompiler = transform => Statement.makeCompiler({
|
|
103
|
+
placeholder: _ => `?`,
|
|
104
|
+
onIdentifier: transform ? _ => escape(transform(_)) : escape,
|
|
105
|
+
onRecordUpdate: () => ["", []],
|
|
106
|
+
onCustom: () => ["", []]
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","names":["Client","SqlError","Statement","sqliteInit","Config","Context","Effect","identity","Layer","Scope","SqliteClient","GenericTag","initEffect","runSync","cached","promise","make","options","gen","_","compiler","makeCompiler","transformQueryNames","transformRows","defaultTransforms","transformResultNames","array","makeConnection","sqlite3","db","mode","oo1","OpfsDb","dieMessage","dbName","openMode","DB","addFinalizer","sync","close","run","sql","params","rowMode","try","results","exec","bind","length","undefined","resultRows","catch","error","runTransform","map","execute","executeValues","executeWithoutTransform","executeRaw","executeStream","export","capi","sqlite3_js_db_export","pointer","semaphore","makeSemaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","as","zipRight","take","tap","scope","release","Object","assign","config","flatMap","layer","scoped","unwrap","escape","defaultEscape","transform","placeholder","onIdentifier","onRecordUpdate","onCustom"],"sources":["../../src/Client.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MA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,CAClBhF,MAAM,CAACgB,IAAI,CAAC;IACVmD,QAAQ;IACR/C,QAAQ;IACRkD;GACD,CAAC,EACF;IACEW,MAAM,EAAEhE,OAAO;IACf2C,MAAM,EAAEtD,MAAM,CAAC4E,OAAO,CAACf,QAAQ,EAAGhD,CAAC,IAAKA,CAAC,CAACyC,MAAM;GACjD,CACF;AACH,CAAC,CAAC;AAEJ;;;;AAIA,OAAO,MAAMuB,KAAK,GAChBF,MAA8C,IAE9CzE,KAAK,CAAC4E,MAAM,CACV1E,YAAY,EACZJ,MAAM,CAAC4E,OAAO,CAAC9E,MAAM,CAACiF,MAAM,CAACJ,MAAM,CAAC,EAAEjE,IAAI,CAAC,CAC5C;AAEH,MAAMsE,MAAM,gBAAGpF,SAAS,CAACqF,aAAa,CAAC,IAAI,CAAC;AAE5C;;;;AAIA,OAAO,MAAMlE,YAAY,GAAImE,SAAiC,IAC5DtF,SAAS,CAACmB,YAAY,CAAC;EACrBoE,WAAW,EAAGtE,CAAC,IAAK,GAAG;EACvBuE,YAAY,EAAEF,SAAS,GAAIrE,CAAC,IAAKmE,MAAM,CAACE,SAAS,CAACrE,CAAC,CAAC,CAAC,GAAGmE,MAAM;EAC9DK,cAAc,EAAEA,CAAA,KAAM,CAAC,EAAE,EAAE,EAAE,CAAC;EAC9BC,QAAQ,EAAEA,CAAA,KAAM,CAAC,EAAE,EAAE,EAAE;CACxB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as Migrator from "@effect/sql/Migrator";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import * as Client from "./Client.js";
|
|
4
|
+
/**
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export * from "@effect/sql/Migrator";
|
|
8
|
+
/**
|
|
9
|
+
* @category constructor
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
export const run = /*#__PURE__*/Migrator.make({
|
|
13
|
+
getClient: Client.SqliteClient,
|
|
14
|
+
ensureTable(sql, table) {
|
|
15
|
+
return sql`
|
|
16
|
+
CREATE TABLE IF NOT EXISTS ${sql(table)} (
|
|
17
|
+
migration_id integer PRIMARY KEY NOT NULL,
|
|
18
|
+
created_at datetime NOT NULL DEFAULT current_timestamp,
|
|
19
|
+
name VARCHAR(255) NOT NULL
|
|
20
|
+
)
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* @category constructor
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export const makeLayer = options => Layer.effectDiscard(run(options));
|
|
29
|
+
//# sourceMappingURL=Migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migrator.js","names":["Migrator","Layer","Client","run","make","getClient","SqliteClient","ensureTable","sql","table","makeLayer","options","effectDiscard"],"sources":["../../src/Migrator.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,QAAQ,MAAM,sBAAsB;AAEhD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,aAAa;AAErC;;;AAGA,cAAc,sBAAsB;AAEpC;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZH,QAAQ,CAACI,IAAI,CAAC;EAChBC,SAAS,EAAEH,MAAM,CAACI,YAAY;EAC9BC,WAAWA,CAACC,GAAG,EAAEC,KAAK;IACpB,OAAOD,GAAG;mCACqBA,GAAG,CAACC,KAAK,CAAC;;;;;KAKxC;EACH;CACD,CAAC;AAEF;;;;AAIA,OAAO,MAAMC,SAAS,GACpBC,OAAiC,IAC+CV,KAAK,CAACW,aAAa,CAACT,GAAG,CAACQ,OAAO,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export * as client from "./Client.js";
|
|
8
|
+
/**
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
export * as error from "@effect/sql/Error";
|
|
12
|
+
/**
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export * as migrator from "./Migrator.js";
|
|
16
|
+
/**
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
export * as resolver from "@effect/sql/Resolver";
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
export * as schema from "@effect/sql/Schema";
|
|
24
|
+
/**
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
export * as statement from "@effect/sql/Statement";
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["client","error","migrator","resolver","schema","statement"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,aAAa;AAErC;;;AAGA,OAAO,KAAKC,KAAK,MAAM,mBAAmB;AAE1C;;;AAGA,OAAO,KAAKC,QAAQ,MAAM,eAAe;AAEzC;;;AAGA,OAAO,KAAKC,QAAQ,MAAM,sBAAsB;AAEhD;;;AAGA,OAAO,KAAKC,MAAM,MAAM,oBAAoB;AAE5C;;;AAGA,OAAO,KAAKC,SAAS,MAAM,uBAAuB","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effect/sql-sqlite-wasm",
|
|
3
|
+
"version": "0.0.0-snapshot-189d4cae80e186661241002ad9d729628096520f",
|
|
4
|
+
"description": "A SQLite toolkit for Effect",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/effect-ts/effect.git",
|
|
9
|
+
"directory": "packages/sql-sqlite-wasm"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": [],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@sqlite.org/sqlite-wasm": "3.45.2-build1"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@effect/sql": "^0.0.0-snapshot-189d4cae80e186661241002ad9d729628096520f",
|
|
17
|
+
"effect": "^0.0.0-snapshot-189d4cae80e186661241002ad9d729628096520f"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/cjs/index.js",
|
|
20
|
+
"module": "./dist/esm/index.js",
|
|
21
|
+
"types": "./dist/dts/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
"./package.json": "./package.json",
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/dts/index.d.ts",
|
|
26
|
+
"import": "./dist/esm/index.js",
|
|
27
|
+
"default": "./dist/cjs/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./Client": {
|
|
30
|
+
"types": "./dist/dts/Client.d.ts",
|
|
31
|
+
"import": "./dist/esm/Client.js",
|
|
32
|
+
"default": "./dist/cjs/Client.js"
|
|
33
|
+
},
|
|
34
|
+
"./Migrator": {
|
|
35
|
+
"types": "./dist/dts/Migrator.d.ts",
|
|
36
|
+
"import": "./dist/esm/Migrator.js",
|
|
37
|
+
"default": "./dist/cjs/Migrator.js"
|
|
38
|
+
},
|
|
39
|
+
"./sqlite-wasm.d": {
|
|
40
|
+
"types": "./dist/dts/sqlite-wasm.d.d.ts",
|
|
41
|
+
"import": "./dist/esm/sqlite-wasm.d.js",
|
|
42
|
+
"default": "./dist/cjs/sqlite-wasm.d.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"typesVersions": {
|
|
46
|
+
"*": {
|
|
47
|
+
"Client": [
|
|
48
|
+
"./dist/dts/Client.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"Migrator": [
|
|
51
|
+
"./dist/dts/Migrator.d.ts"
|
|
52
|
+
],
|
|
53
|
+
"sqlite-wasm.d": [
|
|
54
|
+
"./dist/dts/sqlite-wasm.d.d.ts"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/Client.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Client from "@effect/sql/Client"
|
|
5
|
+
import type { Connection } from "@effect/sql/Connection"
|
|
6
|
+
import { SqlError } from "@effect/sql/Error"
|
|
7
|
+
import * as Statement from "@effect/sql/Statement"
|
|
8
|
+
import type { DB, OpenMode, RowMode } from "@sqlite.org/sqlite-wasm"
|
|
9
|
+
import sqliteInit from "@sqlite.org/sqlite-wasm"
|
|
10
|
+
import * as Config from "effect/Config"
|
|
11
|
+
import type { ConfigError } from "effect/ConfigError"
|
|
12
|
+
import * as Context from "effect/Context"
|
|
13
|
+
import * as Effect from "effect/Effect"
|
|
14
|
+
import { identity } from "effect/Function"
|
|
15
|
+
import * as Layer from "effect/Layer"
|
|
16
|
+
import * as Scope from "effect/Scope"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @category models
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export interface SqliteClient extends Client.Client {
|
|
23
|
+
readonly config: SqliteClientConfig
|
|
24
|
+
readonly export: Effect.Effect<Uint8Array, SqlError>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @category tags
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
31
|
+
export const SqliteClient: Context.Tag<SqliteClient, SqliteClient> = Context.GenericTag(
|
|
32
|
+
"@effect/sql-sqlite-wasm/SqliteClient"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @category models
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
*/
|
|
39
|
+
export type SqliteClientConfig =
|
|
40
|
+
| {
|
|
41
|
+
readonly mode?: "vfs"
|
|
42
|
+
readonly dbName?: string
|
|
43
|
+
readonly openMode?: OpenMode
|
|
44
|
+
readonly transformResultNames?: (str: string) => string
|
|
45
|
+
readonly transformQueryNames?: (str: string) => string
|
|
46
|
+
}
|
|
47
|
+
| {
|
|
48
|
+
readonly mode: "opfs"
|
|
49
|
+
readonly dbName: string
|
|
50
|
+
readonly openMode?: OpenMode
|
|
51
|
+
readonly transformResultNames?: (str: string) => string
|
|
52
|
+
readonly transformQueryNames?: (str: string) => string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface SqliteConnection extends Connection {
|
|
56
|
+
readonly export: Effect.Effect<Uint8Array, SqlError>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const initEffect = Effect.runSync(
|
|
60
|
+
Effect.cached(Effect.promise(() => sqliteInit()))
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @category constructor
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
*/
|
|
67
|
+
export const make = (
|
|
68
|
+
options: SqliteClientConfig
|
|
69
|
+
): Effect.Effect<SqliteClient, never, Scope.Scope> =>
|
|
70
|
+
Effect.gen(function*(_) {
|
|
71
|
+
const compiler = makeCompiler(options.transformQueryNames)
|
|
72
|
+
const transformRows = Client.defaultTransforms(
|
|
73
|
+
options.transformResultNames!
|
|
74
|
+
).array
|
|
75
|
+
|
|
76
|
+
const makeConnection = Effect.gen(function*(_) {
|
|
77
|
+
const sqlite3 = yield* _(initEffect)
|
|
78
|
+
|
|
79
|
+
let db: DB
|
|
80
|
+
if (options.mode === "opfs") {
|
|
81
|
+
if (!sqlite3.oo1.OpfsDb) {
|
|
82
|
+
yield* _(Effect.dieMessage("opfs mode not available"))
|
|
83
|
+
}
|
|
84
|
+
db = new sqlite3.oo1.OpfsDb!(options.dbName, options.openMode ?? "c")
|
|
85
|
+
} else {
|
|
86
|
+
db = new sqlite3.oo1.DB(options.dbName, options.openMode)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
yield* _(Effect.addFinalizer(() => Effect.sync(() => db.close())))
|
|
90
|
+
|
|
91
|
+
const run = (
|
|
92
|
+
sql: string,
|
|
93
|
+
params: ReadonlyArray<Statement.Primitive> = [],
|
|
94
|
+
rowMode: RowMode = "object"
|
|
95
|
+
) =>
|
|
96
|
+
Effect.try({
|
|
97
|
+
try: () => {
|
|
98
|
+
const results: Array<any> = []
|
|
99
|
+
db.exec({
|
|
100
|
+
sql,
|
|
101
|
+
bind: params.length ? params : undefined,
|
|
102
|
+
rowMode,
|
|
103
|
+
resultRows: results
|
|
104
|
+
})
|
|
105
|
+
return results
|
|
106
|
+
},
|
|
107
|
+
catch: (error) => new SqlError({ error })
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const runTransform = options.transformResultNames
|
|
111
|
+
? (sql: string, params?: ReadonlyArray<Statement.Primitive>) => Effect.map(run(sql, params), transformRows)
|
|
112
|
+
: run
|
|
113
|
+
|
|
114
|
+
return identity<SqliteConnection>({
|
|
115
|
+
execute(sql, params) {
|
|
116
|
+
return runTransform(sql, params)
|
|
117
|
+
},
|
|
118
|
+
executeValues(sql, params) {
|
|
119
|
+
return run(sql, params, "array")
|
|
120
|
+
},
|
|
121
|
+
executeWithoutTransform(sql, params) {
|
|
122
|
+
return run(sql, params)
|
|
123
|
+
},
|
|
124
|
+
executeRaw(sql, params) {
|
|
125
|
+
return runTransform(sql, params)
|
|
126
|
+
},
|
|
127
|
+
executeStream() {
|
|
128
|
+
return Effect.dieMessage("executeStream not implemented")
|
|
129
|
+
},
|
|
130
|
+
export: Effect.try({
|
|
131
|
+
try: () => sqlite3.capi.sqlite3_js_db_export(db.pointer),
|
|
132
|
+
catch: (error) => new SqlError({ error })
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const semaphore = yield* _(Effect.makeSemaphore(1))
|
|
138
|
+
const connection = yield* _(makeConnection)
|
|
139
|
+
|
|
140
|
+
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
141
|
+
const transactionAcquirer = Effect.uninterruptibleMask((restore) =>
|
|
142
|
+
Effect.as(
|
|
143
|
+
Effect.zipRight(
|
|
144
|
+
restore(semaphore.take(1)),
|
|
145
|
+
Effect.tap(
|
|
146
|
+
Effect.scope,
|
|
147
|
+
(scope) => Scope.addFinalizer(scope, semaphore.release(1))
|
|
148
|
+
)
|
|
149
|
+
),
|
|
150
|
+
connection
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
return Object.assign(
|
|
155
|
+
Client.make({
|
|
156
|
+
acquirer,
|
|
157
|
+
compiler,
|
|
158
|
+
transactionAcquirer
|
|
159
|
+
}),
|
|
160
|
+
{
|
|
161
|
+
config: options,
|
|
162
|
+
export: Effect.flatMap(acquirer, (_) => _.export)
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @category layers
|
|
169
|
+
* @since 1.0.0
|
|
170
|
+
*/
|
|
171
|
+
export const layer = (
|
|
172
|
+
config: Config.Config.Wrap<SqliteClientConfig>
|
|
173
|
+
): Layer.Layer<SqliteClient, ConfigError> =>
|
|
174
|
+
Layer.scoped(
|
|
175
|
+
SqliteClient,
|
|
176
|
+
Effect.flatMap(Config.unwrap(config), make)
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
const escape = Statement.defaultEscape("\"")
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @category compiler
|
|
183
|
+
* @since 1.0.0
|
|
184
|
+
*/
|
|
185
|
+
export const makeCompiler = (transform?: (_: string) => string) =>
|
|
186
|
+
Statement.makeCompiler({
|
|
187
|
+
placeholder: (_) => `?`,
|
|
188
|
+
onIdentifier: transform ? (_) => escape(transform(_)) : escape,
|
|
189
|
+
onRecordUpdate: () => ["", []],
|
|
190
|
+
onCustom: () => ["", []]
|
|
191
|
+
})
|
package/src/Migrator.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { SqlError } from "@effect/sql/Error"
|
|
5
|
+
import * as Migrator from "@effect/sql/Migrator"
|
|
6
|
+
import type * as Effect from "effect/Effect"
|
|
7
|
+
import * as Layer from "effect/Layer"
|
|
8
|
+
import * as Client from "./Client.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
export * from "@effect/sql/Migrator"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @category constructor
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
export const run: <R>(
|
|
20
|
+
options: Migrator.MigratorOptions<R>
|
|
21
|
+
) => Effect.Effect<
|
|
22
|
+
ReadonlyArray<readonly [id: number, name: string]>,
|
|
23
|
+
SqlError | Migrator.MigrationError,
|
|
24
|
+
Client.SqliteClient | R
|
|
25
|
+
> = Migrator.make({
|
|
26
|
+
getClient: Client.SqliteClient,
|
|
27
|
+
ensureTable(sql, table) {
|
|
28
|
+
return sql`
|
|
29
|
+
CREATE TABLE IF NOT EXISTS ${sql(table)} (
|
|
30
|
+
migration_id integer PRIMARY KEY NOT NULL,
|
|
31
|
+
created_at datetime NOT NULL DEFAULT current_timestamp,
|
|
32
|
+
name VARCHAR(255) NOT NULL
|
|
33
|
+
)
|
|
34
|
+
`
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @category constructor
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
*/
|
|
42
|
+
export const makeLayer = (
|
|
43
|
+
options: Migrator.MigratorOptions
|
|
44
|
+
): Layer.Layer<never, SqlError | Migrator.MigrationError, Client.SqliteClient> => Layer.effectDiscard(run(options))
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export * as client from "./Client.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
export * as error from "@effect/sql/Error"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
export * as migrator from "./Migrator.js"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
export * as resolver from "@effect/sql/Resolver"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export * as schema from "@effect/sql/Schema"
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
export * as statement from "@effect/sql/Statement"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare module "@sqlite.org/sqlite-wasm" {
|
|
6
|
+
export type OpenMode = "c" | "ct" | "w" | "wt" | "r" | "rt"
|
|
7
|
+
export type RowMode = "object" | "array" | "stmt"
|
|
8
|
+
|
|
9
|
+
export interface SqliteHandle {
|
|
10
|
+
readonly _: unique symbol
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class DB {
|
|
14
|
+
constructor(dbName?: string, mode?: OpenMode)
|
|
15
|
+
|
|
16
|
+
readonly pointer: SqliteHandle
|
|
17
|
+
|
|
18
|
+
exec(options: {
|
|
19
|
+
sql: string
|
|
20
|
+
bind?: ReadonlyArray<unknown> | undefined
|
|
21
|
+
rowMode?: RowMode | undefined
|
|
22
|
+
resultRows?: Array<unknown> | undefined
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
close(): void
|
|
26
|
+
}
|
|
27
|
+
class OpfsDb extends DB {}
|
|
28
|
+
|
|
29
|
+
interface OO1 {
|
|
30
|
+
readonly DB: typeof DB
|
|
31
|
+
readonly OpfsDb?: typeof OpfsDb
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface CApi {
|
|
35
|
+
readonly sqlite3_js_db_export: (db: SqliteHandle) => Uint8Array
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SqliteWasm {
|
|
39
|
+
readonly oo1: OO1
|
|
40
|
+
readonly capi: CApi
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const init: () => Promise<SqliteWasm>
|
|
44
|
+
export default init
|
|
45
|
+
}
|