@hocuspocus/extension-sqlite 3.4.6-rc.0 → 3.4.6-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/dist/index.js +0 -58
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-sqlite",
3
3
  "description": "a generic Hocuspocus persistence driver for the sqlite",
4
- "version": "3.4.6-rc.0",
4
+ "version": "3.4.6-rc.2",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/extension-database": "^3.4.6-rc.0",
30
+ "@hocuspocus/extension-database": "^3.4.6-rc.2",
31
31
  "kleur": "^4.1.4",
32
32
  "sqlite3": "^5.1.7"
33
33
  },
package/dist/index.js DELETED
@@ -1,58 +0,0 @@
1
- import { Database } from "@hocuspocus/extension-database";
2
- import sqlite3 from "sqlite3";
3
- import kleur from "kleur";
4
-
5
- //#region packages/extension-sqlite/src/SQLite.ts
6
- const schema = `CREATE TABLE IF NOT EXISTS "documents" (
7
- "name" varchar(255) NOT NULL,
8
- "data" blob NOT NULL,
9
- UNIQUE(name)
10
- )`;
11
- const selectQuery = `
12
- SELECT data FROM "documents" WHERE name = $name ORDER BY rowid DESC
13
- `;
14
- const upsertQuery = `
15
- INSERT INTO "documents" ("name", "data") VALUES ($name, $data)
16
- ON CONFLICT(name) DO UPDATE SET data = $data
17
- `;
18
- const SQLITE_INMEMORY = ":memory:";
19
- var SQLite = class extends Database {
20
- constructor(configuration) {
21
- super({});
22
- this.configuration = {
23
- database: SQLITE_INMEMORY,
24
- schema,
25
- fetch: async ({ documentName }) => {
26
- return new Promise((resolve, reject) => {
27
- this.db?.get(selectQuery, { $name: documentName }, (error, row) => {
28
- if (error) reject(error);
29
- resolve(row?.data);
30
- });
31
- });
32
- },
33
- store: async ({ documentName, state }) => {
34
- this.db?.run(upsertQuery, {
35
- $name: documentName,
36
- $data: state
37
- });
38
- }
39
- };
40
- this.configuration = {
41
- ...this.configuration,
42
- ...configuration
43
- };
44
- }
45
- async onConfigure() {
46
- this.db = new sqlite3.Database(this.configuration.database);
47
- this.db.run(this.configuration.schema);
48
- }
49
- async onListen() {
50
- if (this.configuration.database === SQLITE_INMEMORY) {
51
- console.warn(` ${kleur.yellow("The SQLite extension is configured as an in-memory database. All changes will be lost on restart!")}`);
52
- console.log();
53
- }
54
- }
55
- };
56
-
57
- //#endregion
58
- export { SQLite, schema, selectQuery, upsertQuery };