@medyll/idae-idbql 0.119.0 → 0.120.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/README.md +183 -183
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
# @medyll/idae-idbql
|
|
2
|
-
|
|
3
|
-
A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- MongoDB-like query interface for IndexedDB
|
|
8
|
-
- Strong TypeScript support with full type inference
|
|
9
|
-
- Reactive state management for real-time UI updates
|
|
10
|
-
- Support for complex CRUD operations and advanced querying
|
|
11
|
-
- Flexible data modeling with automatic schema creation
|
|
12
|
-
- Built-in indexing and optimization features
|
|
13
|
-
- Easy integration with front-end frameworks, especially Svelte
|
|
14
|
-
- Robust error handling and logging
|
|
15
|
-
- Versioning and database migration support
|
|
16
|
-
- Support for svelte 5 state
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @medyll/idae-idbql
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Quick Start
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
import { createIdbqDb } from '@medyll/idae-idbql';
|
|
28
|
-
|
|
29
|
-
// Define your data model
|
|
30
|
-
const exampleModel = {
|
|
31
|
-
messages: {
|
|
32
|
-
keyPath: "++id, chatId, created_at",
|
|
33
|
-
ts: {} as ChatMessage,
|
|
34
|
-
},
|
|
35
|
-
chat: {
|
|
36
|
-
keyPath: "&chatId, created_at, dateLastMessage",
|
|
37
|
-
ts: {} as Chat,
|
|
38
|
-
template: {},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// Create a database instance
|
|
43
|
-
const idbqStore = createIdbqDb(exampleModel, 1);
|
|
44
|
-
const { idbql, idbqlState, idbDatabase, idbqModel } = idbqStore.create("myDatabase");
|
|
45
|
-
|
|
46
|
-
// Perform database operations
|
|
47
|
-
async function fetchMessages() {
|
|
48
|
-
const messages = await idbql.messages.where({ chatId: "123" }).toArray();
|
|
49
|
-
console.log(messages);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fetchMessages();
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## API Reference
|
|
56
|
-
|
|
57
|
-
### createIdbqDb(model, version)
|
|
58
|
-
|
|
59
|
-
Creates an IndexedDB database instance with the specified model and version.
|
|
60
|
-
|
|
61
|
-
### idbql
|
|
62
|
-
|
|
63
|
-
The main interface for database operations. Provides methods for each collection defined in your model.
|
|
64
|
-
|
|
65
|
-
### idbqlState
|
|
66
|
-
|
|
67
|
-
A reactive state object that reflects the current state of your database.
|
|
68
|
-
|
|
69
|
-
### idbDatabase
|
|
70
|
-
|
|
71
|
-
Provides low-level access to the IndexedDB instance.
|
|
72
|
-
|
|
73
|
-
### idbqModel
|
|
74
|
-
|
|
75
|
-
Contains the database model definition.
|
|
76
|
-
|
|
77
|
-
## Query Operations
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
// Add a new item
|
|
81
|
-
await idbql.messages.add({ chatId: "123", content: "Hello" });
|
|
82
|
-
|
|
83
|
-
// Update an item
|
|
84
|
-
await idbql.messages.put({ id: 1, content: "Updated message" });
|
|
85
|
-
|
|
86
|
-
// Delete an item
|
|
87
|
-
await idbql.messages.delete(1);
|
|
88
|
-
|
|
89
|
-
// Query items
|
|
90
|
-
const recentMessages = await idbql.messages
|
|
91
|
-
.where({ created_at: { gt: new Date(Date.now() - 86400000) } })
|
|
92
|
-
.toArray();
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Transactions
|
|
96
|
-
|
|
97
|
-
idbql supports complex transactions across multiple object stores:
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
const result = await idbql.transaction(
|
|
101
|
-
["users", "posts"],
|
|
102
|
-
"readwrite",
|
|
103
|
-
async (tx) => {
|
|
104
|
-
const userStore = tx.objectStore("users");
|
|
105
|
-
const postStore = tx.objectStore("posts");
|
|
106
|
-
|
|
107
|
-
const userId = await userStore.add({ name: "Alice", email: "alice@example.com" });
|
|
108
|
-
const postId = await postStore.add({ userId, title: "Alice's First Post", content: "Hello, World!" });
|
|
109
|
-
|
|
110
|
-
return { userId, postId };
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Reactive State Management
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
import { derived } from 'svelte/store';
|
|
119
|
-
|
|
120
|
-
const activeUsers = $derived(idbqlState.users.where({ isActive: true }));
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Integration with Svelte
|
|
124
|
-
|
|
125
|
-
```svelte
|
|
126
|
-
<script>
|
|
127
|
-
import { derived } from 'svelte/store';
|
|
128
|
-
import { idbqlState } from './store';
|
|
129
|
-
|
|
130
|
-
const messages = $derived(idbqlState.messages.where({ chatId: "123" }));
|
|
131
|
-
</script>
|
|
132
|
-
|
|
133
|
-
{#each $messages as message}
|
|
134
|
-
<p>{message.content}</p>
|
|
135
|
-
{/each}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Versioning and Migrations
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
const idbqStore = createIdbqDb(myModel, 2);
|
|
142
|
-
const { idbDatabase } = idbqStore.create("myDb", {
|
|
143
|
-
upgrade(oldVersion, newVersion, transaction) {
|
|
144
|
-
if (oldVersion < 2) {
|
|
145
|
-
const userStore = transaction.objectStore("users");
|
|
146
|
-
userStore.createIndex("emailIndex", "email", { unique: true });
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Error Handling
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
try {
|
|
156
|
-
await idbql.users.add({ username: "existing_user" });
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (error instanceof UniqueConstraintError) {
|
|
159
|
-
console.error("Username already exists");
|
|
160
|
-
} else {
|
|
161
|
-
console.error("An unexpected error occurred", error);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## Performance Tips
|
|
167
|
-
|
|
168
|
-
- Use appropriate indexes
|
|
169
|
-
- Limit result sets with `.limit(n)`
|
|
170
|
-
- Use `.count()` instead of `.toArray().length`
|
|
171
|
-
- Optimize queries to use indexes effectively
|
|
172
|
-
|
|
173
|
-
## Contributing
|
|
174
|
-
|
|
175
|
-
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
|
|
176
|
-
|
|
177
|
-
## License
|
|
178
|
-
|
|
179
|
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
180
|
-
|
|
181
|
-
## Support
|
|
182
|
-
|
|
183
|
-
If you encounter any issues or have questions, please file an issue on the GitHub repository.
|
|
1
|
+
# @medyll/idae-idbql
|
|
2
|
+
|
|
3
|
+
A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- MongoDB-like query interface for IndexedDB
|
|
8
|
+
- Strong TypeScript support with full type inference
|
|
9
|
+
- Reactive state management for real-time UI updates
|
|
10
|
+
- Support for complex CRUD operations and advanced querying
|
|
11
|
+
- Flexible data modeling with automatic schema creation
|
|
12
|
+
- Built-in indexing and optimization features
|
|
13
|
+
- Easy integration with front-end frameworks, especially Svelte
|
|
14
|
+
- Robust error handling and logging
|
|
15
|
+
- Versioning and database migration support
|
|
16
|
+
- Support for svelte 5 state
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @medyll/idae-idbql
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { createIdbqDb } from '@medyll/idae-idbql';
|
|
28
|
+
|
|
29
|
+
// Define your data model
|
|
30
|
+
const exampleModel = {
|
|
31
|
+
messages: {
|
|
32
|
+
keyPath: "++id, chatId, created_at",
|
|
33
|
+
ts: {} as ChatMessage,
|
|
34
|
+
},
|
|
35
|
+
chat: {
|
|
36
|
+
keyPath: "&chatId, created_at, dateLastMessage",
|
|
37
|
+
ts: {} as Chat,
|
|
38
|
+
template: {},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Create a database instance
|
|
43
|
+
const idbqStore = createIdbqDb(exampleModel, 1);
|
|
44
|
+
const { idbql, idbqlState, idbDatabase, idbqModel } = idbqStore.create("myDatabase");
|
|
45
|
+
|
|
46
|
+
// Perform database operations
|
|
47
|
+
async function fetchMessages() {
|
|
48
|
+
const messages = await idbql.messages.where({ chatId: "123" }).toArray();
|
|
49
|
+
console.log(messages);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fetchMessages();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API Reference
|
|
56
|
+
|
|
57
|
+
### createIdbqDb(model, version)
|
|
58
|
+
|
|
59
|
+
Creates an IndexedDB database instance with the specified model and version.
|
|
60
|
+
|
|
61
|
+
### idbql
|
|
62
|
+
|
|
63
|
+
The main interface for database operations. Provides methods for each collection defined in your model.
|
|
64
|
+
|
|
65
|
+
### idbqlState
|
|
66
|
+
|
|
67
|
+
A reactive state object that reflects the current state of your database.
|
|
68
|
+
|
|
69
|
+
### idbDatabase
|
|
70
|
+
|
|
71
|
+
Provides low-level access to the IndexedDB instance.
|
|
72
|
+
|
|
73
|
+
### idbqModel
|
|
74
|
+
|
|
75
|
+
Contains the database model definition.
|
|
76
|
+
|
|
77
|
+
## Query Operations
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Add a new item
|
|
81
|
+
await idbql.messages.add({ chatId: "123", content: "Hello" });
|
|
82
|
+
|
|
83
|
+
// Update an item
|
|
84
|
+
await idbql.messages.put({ id: 1, content: "Updated message" });
|
|
85
|
+
|
|
86
|
+
// Delete an item
|
|
87
|
+
await idbql.messages.delete(1);
|
|
88
|
+
|
|
89
|
+
// Query items
|
|
90
|
+
const recentMessages = await idbql.messages
|
|
91
|
+
.where({ created_at: { gt: new Date(Date.now() - 86400000) } })
|
|
92
|
+
.toArray();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Transactions
|
|
96
|
+
|
|
97
|
+
idbql supports complex transactions across multiple object stores:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const result = await idbql.transaction(
|
|
101
|
+
["users", "posts"],
|
|
102
|
+
"readwrite",
|
|
103
|
+
async (tx) => {
|
|
104
|
+
const userStore = tx.objectStore("users");
|
|
105
|
+
const postStore = tx.objectStore("posts");
|
|
106
|
+
|
|
107
|
+
const userId = await userStore.add({ name: "Alice", email: "alice@example.com" });
|
|
108
|
+
const postId = await postStore.add({ userId, title: "Alice's First Post", content: "Hello, World!" });
|
|
109
|
+
|
|
110
|
+
return { userId, postId };
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Reactive State Management
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { derived } from 'svelte/store';
|
|
119
|
+
|
|
120
|
+
const activeUsers = $derived(idbqlState.users.where({ isActive: true }));
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Integration with Svelte
|
|
124
|
+
|
|
125
|
+
```svelte
|
|
126
|
+
<script>
|
|
127
|
+
import { derived } from 'svelte/store';
|
|
128
|
+
import { idbqlState } from './store';
|
|
129
|
+
|
|
130
|
+
const messages = $derived(idbqlState.messages.where({ chatId: "123" }));
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
{#each $messages as message}
|
|
134
|
+
<p>{message.content}</p>
|
|
135
|
+
{/each}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Versioning and Migrations
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const idbqStore = createIdbqDb(myModel, 2);
|
|
142
|
+
const { idbDatabase } = idbqStore.create("myDb", {
|
|
143
|
+
upgrade(oldVersion, newVersion, transaction) {
|
|
144
|
+
if (oldVersion < 2) {
|
|
145
|
+
const userStore = transaction.objectStore("users");
|
|
146
|
+
userStore.createIndex("emailIndex", "email", { unique: true });
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Error Handling
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
try {
|
|
156
|
+
await idbql.users.add({ username: "existing_user" });
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error instanceof UniqueConstraintError) {
|
|
159
|
+
console.error("Username already exists");
|
|
160
|
+
} else {
|
|
161
|
+
console.error("An unexpected error occurred", error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Performance Tips
|
|
167
|
+
|
|
168
|
+
- Use appropriate indexes
|
|
169
|
+
- Limit result sets with `.limit(n)`
|
|
170
|
+
- Use `.count()` instead of `.toArray().length`
|
|
171
|
+
- Optimize queries to use indexes effectively
|
|
172
|
+
|
|
173
|
+
## Contributing
|
|
174
|
+
|
|
175
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
180
|
+
|
|
181
|
+
## Support
|
|
182
|
+
|
|
183
|
+
If you encounter any issues or have questions, please file an issue on the GitHub repository.
|
|
184
184
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-idbql",
|
|
3
3
|
"scope": "@medyll",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.120.0",
|
|
5
5
|
"description": "A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications, offering a MongoDB-like query interface, strong TypeScript support, reactive state management, and easy integration with front-end frameworks like Svelte.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite dev",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"svelte": "^5.0.0-next"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@medyll/idae-prettier-config": "^1.2.
|
|
33
|
+
"@medyll/idae-prettier-config": "^1.2.1",
|
|
34
34
|
"@sveltejs/adapter-auto": "^6.0.0",
|
|
35
35
|
"@sveltejs/kit": "^2.20.7",
|
|
36
36
|
"@sveltejs/package": "^2.3.11",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
45
|
"type": "module",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@medyll/idae-query": "^0.
|
|
47
|
+
"@medyll/idae-query": "^0.121.0"
|
|
48
48
|
}
|
|
49
49
|
}
|