deepbase-sqlite 3.0.6 → 3.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepbase-sqlite",
3
- "version": "3.0.6",
3
+ "version": "3.1.0",
4
4
  "description": "⚡ DeepBase SQLite - SQLite database driver",
5
5
  "type": "module",
6
6
  "main": "src/index.cjs",
@@ -15,7 +15,7 @@
15
15
  "better-sqlite3": "^11.8.1"
16
16
  },
17
17
  "peerDependencies": {
18
- "deepbase": "^3.0.6"
18
+ "deepbase": "^3.1.0"
19
19
  },
20
20
  "scripts": {
21
21
  "test": "mocha test/test.js"
@@ -2,7 +2,6 @@ import { DeepBaseDriver } from 'deepbase';
2
2
  import Database from 'better-sqlite3';
3
3
  import fs from 'fs';
4
4
  import * as pathModule from 'path';
5
- import { customAlphabet } from 'nanoid';
6
5
 
7
6
  export class SqliteDriver extends DeepBaseDriver {
8
7
  static _instances = {};
@@ -12,7 +11,6 @@ export class SqliteDriver extends DeepBaseDriver {
12
11
 
13
12
  this.name = name || "default";
14
13
  this.path = path || './db';
15
- this.nanoid = customAlphabet(this.nidAlphabet, this.nidLength);
16
14
 
17
15
  this.path = pathModule.resolve(this.path);
18
16
  this.fileName = pathModule.join(this.path, `${this.name}.db`);
@@ -158,14 +156,6 @@ export class SqliteDriver extends DeepBaseDriver {
158
156
  return this.set(...args, func(await this.get(...args)));
159
157
  }
160
158
 
161
- _pathToKey(path) {
162
- return path.join('.');
163
- }
164
-
165
- _keyToPath(key) {
166
- return key.split('.');
167
- }
168
-
169
159
  _getRootObject() {
170
160
  const rows = this.getAllStmt.all();
171
161
  const result = {};
package/test/test.js CHANGED
@@ -97,6 +97,65 @@ describe('SqliteDriver', function() {
97
97
  });
98
98
  });
99
99
 
100
+ describe('Keys with Dots', function() {
101
+ it('should handle keys containing dots', async function() {
102
+ const setResult = await db.set('value', 'martin.clasen@gmail.com', 1);
103
+
104
+ assert.strictEqual(setResult.length, 2);
105
+ assert.strictEqual(setResult[0], 'value');
106
+ assert.strictEqual(setResult[1], 'martin.clasen@gmail.com');
107
+
108
+ const getValue = await db.get('value');
109
+ assert.deepStrictEqual(getValue, { 'martin.clasen@gmail.com': 1 });
110
+ });
111
+
112
+ it('should handle keys with multiple dots', async function() {
113
+ await db.set('config', 'api.prod.endpoint', 'https://api.example.com');
114
+ const endpoint = await db.get('config', 'api.prod.endpoint');
115
+ assert.strictEqual(endpoint, 'https://api.example.com');
116
+ });
117
+
118
+ it('should handle nested paths with dots in keys', async function() {
119
+ await db.set('users', 'john.doe@example.com', 'name', 'John Doe');
120
+ await db.set('users', 'john.doe@example.com', 'age', 30);
121
+
122
+ const user = await db.get('users', 'john.doe@example.com');
123
+ assert.deepStrictEqual(user, { name: 'John Doe', age: 30 });
124
+ });
125
+
126
+ it('should handle dots in first level keys', async function() {
127
+ await db.set('config.prod', 'value', 100);
128
+ const configProd = await db.get('config.prod');
129
+ assert.deepStrictEqual(configProd, { value: 100 });
130
+ });
131
+
132
+ it('should distinguish between dots in keys and path separators', async function() {
133
+ // Set a regular nested path
134
+ await db.set('users', 'alice', 'email', 'alice@example.com');
135
+
136
+ // Set a key with dots at the same level
137
+ await db.set('users', 'john.doe@company.com', 'email', 'john@work.com');
138
+
139
+ const users = await db.get('users');
140
+ assert.strictEqual(users.alice.email, 'alice@example.com');
141
+ assert.strictEqual(users['john.doe@company.com'].email, 'john@work.com');
142
+ assert.strictEqual(Object.keys(users).length, 2);
143
+ });
144
+
145
+ it('should delete keys containing dots', async function() {
146
+ await db.set('emails', 'user.name@domain.com', 'verified', true);
147
+ await db.set('emails', 'other@email.com', 'verified', false);
148
+
149
+ await db.del('emails', 'user.name@domain.com');
150
+
151
+ const email1 = await db.get('emails', 'user.name@domain.com');
152
+ const email2 = await db.get('emails', 'other@email.com');
153
+
154
+ assert.strictEqual(email1, null);
155
+ assert.deepStrictEqual(email2, { verified: false });
156
+ });
157
+ });
158
+
100
159
  describe('Delete Operations', function() {
101
160
  it('should delete a key', async function() {
102
161
  await db.set('temp', 'value');