@nymphjs/driver-sqlite3 1.0.0-beta.106 → 1.0.0-beta.108

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/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-beta.108](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.107...v1.0.0-beta.108) (2026-02-15)
7
+
8
+ ### Bug Fixes
9
+
10
+ - add column syntax in sqlite ([c1fa882](https://github.com/sciactive/nymphjs/commit/c1fa882b8ed9ee11f72ae3a9a902627186403de5))
11
+
12
+ # [1.0.0-beta.107](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.106...v1.0.0-beta.107) (2026-02-13)
13
+
14
+ ### Features
15
+
16
+ - move tilmeld fields into columns in entities tables ([5f46048](https://github.com/sciactive/nymphjs/commit/5f46048c3e04839ca9a8b81f71a950b9086d0a41))
17
+ - update packages and fix all new issues ([0e9d17c](https://github.com/sciactive/nymphjs/commit/0e9d17c6e2db12c11bdfb559031719c1b52b5fa1))
18
+
6
19
  # [1.0.0-beta.106](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.105...v1.0.0-beta.106) (2025-12-05)
7
20
 
8
21
  ### Bug Fixes
@@ -45,6 +45,8 @@ export default class SQLite3Driver extends NymphDriver {
45
45
  */
46
46
  isConnected(): boolean;
47
47
  private createEntitiesTable;
48
+ private addTilmeldColumnsAndIndexes;
49
+ private createEntitiesTilmeldIndexes;
48
50
  private createDataTable;
49
51
  private createReferencesTable;
50
52
  private createTokensTable;
@@ -119,6 +121,14 @@ export default class SQLite3Driver extends NymphDriver {
119
121
  sdata: SerializedEntityData;
120
122
  etype: string;
121
123
  }): Promise<void>;
124
+ importEntityTilmeldAC(entity: {
125
+ guid: string;
126
+ cdate: number;
127
+ mdate: number;
128
+ tags: string[];
129
+ sdata: SerializedEntityData;
130
+ etype: string;
131
+ }): Promise<void>;
122
132
  private importEntityInternal;
123
133
  importUID({ name, value }: {
124
134
  name: string;
@@ -131,7 +141,7 @@ export default class SQLite3Driver extends NymphDriver {
131
141
  setUID(name: string, curUid: number): Promise<boolean>;
132
142
  internalTransaction(name: string): Promise<void>;
133
143
  startTransaction(name: string): Promise<import("@nymphjs/nymph").Nymph>;
134
- needsMigration(): Promise<'json' | 'tokens' | false>;
135
- liveMigration(_migrationType: 'tokenTables'): Promise<void>;
144
+ needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
145
+ liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns'): Promise<void>;
136
146
  }
137
147
  export {};
@@ -179,10 +179,32 @@ export default class SQLite3Driver extends NymphDriver {
179
179
  }
180
180
  createEntitiesTable(etype) {
181
181
  // Create the entity table.
182
- this.queryRun(`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("guid" CHARACTER(24) PRIMARY KEY, "tags" TEXT, "cdate" REAL NOT NULL, "mdate" REAL NOT NULL);`);
182
+ this.queryRun(`CREATE TABLE IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("guid" CHARACTER(24) PRIMARY KEY, "tags" TEXT, "cdate" REAL NOT NULL, "mdate" REAL NOT NULL, "user" CHARACTER(24), "group" CHARACTER(24), "acUser" INT(1), "acGroup" INT(1), "acOther" INT(1), "acRead" TEXT, "acWrite" TEXT, "acFull" TEXT);`);
183
183
  this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_cdate`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("cdate");`);
184
184
  this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_mdate`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("mdate");`);
185
185
  this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_tags`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("tags");`);
186
+ this.createEntitiesTilmeldIndexes(etype);
187
+ }
188
+ addTilmeldColumnsAndIndexes(etype) {
189
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "user" CHARACTER(24);`);
190
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "group" CHARACTER(24);`);
191
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "acUser" INT(1);`);
192
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "acGroup" INT(1);`);
193
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "acOther" INT(1);`);
194
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "acRead" TEXT;`);
195
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "acWrite" TEXT;`);
196
+ this.queryRun(`ALTER TABLE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN "acFull" TEXT;`);
197
+ this.createEntitiesTilmeldIndexes(etype);
198
+ }
199
+ createEntitiesTilmeldIndexes(etype) {
200
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_user_acUser`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("user", "acUser");`);
201
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_group_acGroup`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("group", "acGroup");`);
202
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_acUser`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("acUser");`);
203
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_acGroup`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("acGroup");`);
204
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_acOther`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("acOther");`);
205
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_acRead`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("acRead");`);
206
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_acWrite`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("acWrite");`);
207
+ this.queryRun(`CREATE INDEX IF NOT EXISTS ${SQLite3Driver.escape(`${this.prefix}entities_${etype}_id_acFull`)} ON ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("acFull");`);
186
208
  }
187
209
  createDataTable(etype) {
188
210
  // Create the data table.
@@ -1651,14 +1673,17 @@ export default class SQLite3Driver extends NymphDriver {
1651
1673
  return result?.cur_uid ?? null;
1652
1674
  }
1653
1675
  async importEntity(entity) {
1654
- return await this.importEntityInternal(entity, false);
1676
+ return await this.importEntityInternal(entity);
1655
1677
  }
1656
1678
  async importEntityTokens(entity) {
1657
- return await this.importEntityInternal(entity, true);
1679
+ return await this.importEntityInternal(entity, { only: 'tokens' });
1680
+ }
1681
+ async importEntityTilmeldAC(entity) {
1682
+ return await this.importEntityInternal(entity, { only: 'tilmeldAC' });
1658
1683
  }
1659
- async importEntityInternal({ guid, cdate, mdate, tags, sdata, etype, }, onlyTokens) {
1684
+ async importEntityInternal({ guid, cdate, mdate, tags, sdata, etype, }, { only = undefined } = {}) {
1660
1685
  try {
1661
- if (!onlyTokens) {
1686
+ if (only == null) {
1662
1687
  this.queryRun(`DELETE FROM ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} WHERE "guid"=@guid;`, {
1663
1688
  etypes: [etype],
1664
1689
  params: {
@@ -1678,13 +1703,15 @@ export default class SQLite3Driver extends NymphDriver {
1678
1703
  },
1679
1704
  });
1680
1705
  }
1681
- this.queryRun(`DELETE FROM ${SQLite3Driver.escape(`${this.prefix}tokens_${etype}`)} WHERE "guid"=@guid;`, {
1682
- etypes: [etype],
1683
- params: {
1684
- guid,
1685
- },
1686
- });
1687
- if (!onlyTokens) {
1706
+ if (only == null || only === 'tokens') {
1707
+ this.queryRun(`DELETE FROM ${SQLite3Driver.escape(`${this.prefix}tokens_${etype}`)} WHERE "guid"=@guid;`, {
1708
+ etypes: [etype],
1709
+ params: {
1710
+ guid,
1711
+ },
1712
+ });
1713
+ }
1714
+ if (only == null) {
1688
1715
  this.queryRun(`DELETE FROM ${SQLite3Driver.escape(`${this.prefix}uniques_${etype}`)} WHERE "guid"=@guid;`, {
1689
1716
  etypes: [etype],
1690
1717
  params: {
@@ -1692,14 +1719,23 @@ export default class SQLite3Driver extends NymphDriver {
1692
1719
  },
1693
1720
  });
1694
1721
  }
1695
- if (!onlyTokens) {
1696
- this.queryRun(`INSERT INTO ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate") VALUES (@guid, @tags, @cdate, @mdate);`, {
1722
+ if (only == null) {
1723
+ let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull } = this.removeAndReturnACValues(etype, {}, sdata);
1724
+ this.queryRun(`INSERT INTO ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate", "user", "group", "acUser", "acGroup", "acOther", "acRead", "acWrite", "acFull") VALUES (@guid, @tags, @cdate, @mdate, @user, @group, @acUser, @acGroup, @acOther, @acRead, @acWrite, @acFull);`, {
1697
1725
  etypes: [etype],
1698
1726
  params: {
1699
1727
  guid,
1700
1728
  tags: ',' + tags.join(',') + ',',
1701
1729
  cdate,
1702
1730
  mdate,
1731
+ user,
1732
+ group,
1733
+ acUser,
1734
+ acGroup,
1735
+ acOther,
1736
+ acRead: acRead && ',' + acRead.join(',') + ',',
1737
+ acWrite: acWrite && ',' + acWrite.join(',') + ',',
1738
+ acFull: acFull && ',' + acFull.join(',') + ',',
1703
1739
  },
1704
1740
  });
1705
1741
  for (const name in sdata) {
@@ -1739,45 +1775,64 @@ export default class SQLite3Driver extends NymphDriver {
1739
1775
  }
1740
1776
  }
1741
1777
  }
1778
+ if (only === 'tilmeldAC') {
1779
+ let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull } = this.removeAndReturnACValues(etype, {}, sdata);
1780
+ this.queryRun(`UPDATE OR IGNORE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} SET "user"=@user, "group"=@group, "acUser"=@acUser, "acGroup"=@acGroup, "acOther"=@acOther, "acRead"=@acRead, "acWrite"=@acWrite, "acFull"=@acFull WHERE "guid"=@guid;`, {
1781
+ etypes: [etype],
1782
+ params: {
1783
+ user,
1784
+ group,
1785
+ acUser,
1786
+ acGroup,
1787
+ acOther,
1788
+ acRead: acRead && ',' + acRead.join(',') + ',',
1789
+ acWrite: acWrite && ',' + acWrite.join(',') + ',',
1790
+ acFull: acFull && ',' + acFull.join(',') + ',',
1791
+ guid,
1792
+ },
1793
+ });
1794
+ }
1742
1795
  const EntityClass = this.nymph.getEntityClassByEtype(etype);
1743
- for (let name in sdata) {
1744
- let tokenString = null;
1745
- try {
1746
- tokenString = EntityClass.getFTSText(name, JSON.parse(sdata[name]));
1747
- }
1748
- catch (e) {
1749
- // Ignore error.
1750
- }
1751
- if (tokenString != null) {
1752
- const tokens = this.tokenizer.tokenize(tokenString);
1753
- while (tokens.length) {
1754
- const currentTokens = tokens.splice(0, 100);
1755
- const params = {
1756
- guid,
1757
- name,
1758
- };
1759
- const values = [];
1760
- for (let i = 0; i < currentTokens.length; i++) {
1761
- const token = currentTokens[i];
1762
- params['token' + i] = token.token;
1763
- params['position' + i] = token.position;
1764
- params['stem' + i] = token.stem ? 1 : 0;
1765
- values.push('(@guid, @name, @token' +
1766
- i +
1767
- ', @position' +
1768
- i +
1769
- ', @stem' +
1770
- i +
1771
- ')');
1796
+ if (only == null || only === 'tokens') {
1797
+ for (let name in sdata) {
1798
+ let tokenString = null;
1799
+ try {
1800
+ tokenString = EntityClass.getFTSText(name, JSON.parse(sdata[name]));
1801
+ }
1802
+ catch (e) {
1803
+ // Ignore error.
1804
+ }
1805
+ if (tokenString != null) {
1806
+ const tokens = this.tokenizer.tokenize(tokenString);
1807
+ while (tokens.length) {
1808
+ const currentTokens = tokens.splice(0, 100);
1809
+ const params = {
1810
+ guid,
1811
+ name,
1812
+ };
1813
+ const values = [];
1814
+ for (let i = 0; i < currentTokens.length; i++) {
1815
+ const token = currentTokens[i];
1816
+ params['token' + i] = token.token;
1817
+ params['position' + i] = token.position;
1818
+ params['stem' + i] = token.stem ? 1 : 0;
1819
+ values.push('(@guid, @name, @token' +
1820
+ i +
1821
+ ', @position' +
1822
+ i +
1823
+ ', @stem' +
1824
+ i +
1825
+ ')');
1826
+ }
1827
+ this.queryRun(`INSERT INTO ${SQLite3Driver.escape(`${this.prefix}tokens_${etype}`)} ("guid", "name", "token", "position", "stem") VALUES ${values.join(', ')};`, {
1828
+ etypes: [etype],
1829
+ params,
1830
+ });
1772
1831
  }
1773
- this.queryRun(`INSERT INTO ${SQLite3Driver.escape(`${this.prefix}tokens_${etype}`)} ("guid", "name", "token", "position", "stem") VALUES ${values.join(', ')};`, {
1774
- etypes: [etype],
1775
- params,
1776
- });
1777
1832
  }
1778
1833
  }
1779
1834
  }
1780
- if (!onlyTokens) {
1835
+ if (only == null) {
1781
1836
  const uniques = await EntityClass.getUniques({
1782
1837
  guid,
1783
1838
  cdate,
@@ -2007,12 +2062,21 @@ export default class SQLite3Driver extends NymphDriver {
2007
2062
  Object.keys(sdata).length === 0) {
2008
2063
  return false;
2009
2064
  }
2010
- this.queryRun(`INSERT INTO ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate") VALUES (@guid, @tags, @cdate, @cdate);`, {
2065
+ let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull, } = this.removeAndReturnACValues(etype, data, sdata);
2066
+ this.queryRun(`INSERT INTO ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate", "user", "group", "acUser", "acGroup", "acOther", "acRead", "acWrite", "acFull") VALUES (@guid, @tags, @cdate, @cdate, @user, @group, @acUser, @acGroup, @acOther, @acRead, @acWrite, @acFull);`, {
2011
2067
  etypes: [etype],
2012
2068
  params: {
2013
2069
  guid,
2014
2070
  tags: ',' + tags.join(',') + ',',
2015
2071
  cdate,
2072
+ user,
2073
+ group,
2074
+ acUser,
2075
+ acGroup,
2076
+ acOther,
2077
+ acRead: acRead && ',' + acRead.join(',') + ',',
2078
+ acWrite: acWrite && ',' + acWrite.join(',') + ',',
2079
+ acFull: acFull && ',' + acFull.join(',') + ',',
2016
2080
  },
2017
2081
  });
2018
2082
  insertData(guid, data, sdata, uniques, etype);
@@ -2022,11 +2086,20 @@ export default class SQLite3Driver extends NymphDriver {
2022
2086
  Object.keys(sdata).length === 0) {
2023
2087
  return false;
2024
2088
  }
2025
- const info = this.queryRun(`UPDATE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} SET "tags"=@tags, "mdate"=@mdate WHERE "guid"=@guid AND "mdate" <= @emdate;`, {
2089
+ let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull, } = this.removeAndReturnACValues(etype, data, sdata);
2090
+ const info = this.queryRun(`UPDATE ${SQLite3Driver.escape(`${this.prefix}entities_${etype}`)} SET "tags"=@tags, "mdate"=@mdate, "user"=@user, "group"=@group, "acUser"=@acUser, "acGroup"=@acGroup, "acOther"=@acOther, "acRead"=@acRead, "acWrite"=@acWrite, "acFull"=@acFull WHERE "guid"=@guid AND "mdate" <= @emdate;`, {
2026
2091
  etypes: [etype],
2027
2092
  params: {
2028
2093
  tags: ',' + tags.join(',') + ',',
2029
2094
  mdate,
2095
+ user,
2096
+ group,
2097
+ acUser,
2098
+ acGroup,
2099
+ acOther,
2100
+ acRead: acRead && ',' + acRead.join(',') + ',',
2101
+ acWrite: acWrite && ',' + acWrite.join(',') + ',',
2102
+ acFull: acFull && ',' + acFull.join(',') + ',',
2030
2103
  guid,
2031
2104
  emdate: Number(entity.mdate),
2032
2105
  },
@@ -2142,12 +2215,35 @@ export default class SQLite3Driver extends NymphDriver {
2142
2215
  if (!table2 || !table2.name) {
2143
2216
  return 'tokens';
2144
2217
  }
2218
+ const table3 = this.queryGet("SELECT `name` FROM `sqlite_master` WHERE `type`='table' AND `name` LIKE @prefix LIMIT 1;", {
2219
+ params: {
2220
+ prefix: this.prefix + 'entities_' + '%',
2221
+ },
2222
+ });
2223
+ if (table3?.name) {
2224
+ const result = this.queryGet("SELECT 1 AS `exists` FROM pragma_table_info(@table) WHERE `name`='user';", {
2225
+ params: {
2226
+ table: table3.name,
2227
+ },
2228
+ });
2229
+ if (!result?.exists) {
2230
+ return 'tilmeldColumns';
2231
+ }
2232
+ }
2145
2233
  return false;
2146
2234
  }
2147
- async liveMigration(_migrationType) {
2148
- const etypes = await this.getEtypes();
2149
- for (let etype of etypes) {
2150
- this.createTokensTable(etype);
2235
+ async liveMigration(migrationType) {
2236
+ if (migrationType === 'tokenTables') {
2237
+ const etypes = await this.getEtypes();
2238
+ for (let etype of etypes) {
2239
+ this.createTokensTable(etype);
2240
+ }
2241
+ }
2242
+ else if (migrationType === 'tilmeldColumns') {
2243
+ const etypes = await this.getEtypes();
2244
+ for (let etype of etypes) {
2245
+ this.addTilmeldColumnsAndIndexes(etype);
2246
+ }
2151
2247
  }
2152
2248
  }
2153
2249
  }