Skip to content

Commit 0a1d0d5

Browse files
committed
docs(readme): refresh documentation and build configuration
- Adjust deno.json imports for new directory structure - Update README badges and formatting - Update build.config.ts entries for core/ and query/ modules - Revise USAGE.md examples with latest query patterns
1 parent 44262de commit 0a1d0d5

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const adults = db.where('age >= 18').get()
5858
const firstJohn = db.where('name = John').first()
5959
```
6060

61-
- [USAGE.md](USAGE.md) for more examples and query operator details.
61+
See [USAGE.md](USAGE.md) for more examples and query operator details.
6262

6363
## Build
6464

USAGE.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@ Querying, updating, and deleting records for `@neabyte/jsonary`.
99
- [Nested Fields (Dot Paths)](#nested-fields-dot-paths)
1010
- [CRUD API](#crud-api)
1111
- [Query Builder API](#query-builder-api)
12+
- [Chaining `where()`](#chaining-where)
1213
- [Notes and Limits](#notes-and-limits)
1314

1415
## Quick Start
1516

1617
```typescript
18+
// Import Jsonary
1719
import Jsonary from '@neabyte/jsonary'
1820

21+
// Create database instance
1922
const db = new Jsonary({ path: './data.json' })
2023

24+
// Insert records
2125
db.insert({ name: 'John', age: 30, profile: { role: 'user', active: false } })
2226
db.insert({ name: 'Jane', age: 25, profile: { role: 'admin', active: true } })
2327

28+
// Query with dot-path nested field
2429
const admins = db.where('profile.role = admin').get()
30+
31+
// Get first match
2532
const firstAdult = db.where('age >= 18').first()
33+
34+
// Count matching records
2635
const countActive = db.where('profile.active = true').count()
2736
```
2837

@@ -43,8 +52,11 @@ Supported operators in string conditions:
4352
Examples:
4453

4554
```typescript
55+
// Comparison operators
4656
db.where('age >= 18').get()
4757
db.where('name != John').get()
58+
59+
// String matching operators
4860
db.where('name contains "oh"').get()
4961
db.where('name startsWith J').get()
5062
db.where('name endsWith "e"').get()
@@ -58,14 +70,18 @@ db.where('name endsWith "e"').get()
5870
You can query nested properties using dot paths:
5971

6072
```typescript
73+
// Query nested object properties
6174
db.where('profile.role = admin').get()
6275
db.where('profile.settings.theme = dark').get()
6376
```
6477

6578
You can also update nested properties using dot paths:
6679

6780
```typescript
81+
// Update nested properties via dot-path
6882
db.updateWhere('name = John', { 'profile.active': true })
83+
84+
// Works with query builder too
6985
db.where('profile.role = admin').update({ 'profile.verified': true })
7086
```
7187

@@ -84,6 +100,7 @@ const db = new Jsonary({ path: './data.json' })
84100
Insert one record.
85101

86102
```typescript
103+
// Insert single record
87104
db.insert({ name: 'John', age: 30 })
88105
```
89106

@@ -92,6 +109,7 @@ db.insert({ name: 'John', age: 30 })
92109
Insert multiple records.
93110

94111
```typescript
112+
// Insert multiple records at once
95113
db.insertMany([{ name: 'Jane' }, { name: 'Bob' }])
96114
```
97115

@@ -100,6 +118,7 @@ db.insertMany([{ name: 'Jane' }, { name: 'Bob' }])
100118
Return all records (copy).
101119

102120
```typescript
121+
// Get all records (returns a copy)
103122
const all = db.get()
104123
```
105124

@@ -108,22 +127,32 @@ const all = db.get()
108127
Update records matching condition. Returns number of updated records.
109128

110129
```typescript
130+
// Update records where age is greater than 30
111131
const updated = db.updateWhere('age > 30', { status: 'senior' })
132+
133+
// Update records where age is greater than 30 using a function predicate
134+
const updatedFn = db.updateWhere(item => (item.age as number) > 30, { status: 'senior' })
112135
```
113136

114137
### `db.deleteWhere(condition)`
115138

116139
Delete records matching condition. Returns number of deleted records.
117140

118141
```typescript
142+
// Delete by string condition
119143
const deleted = db.deleteWhere('age < 18')
144+
145+
// Delete by function predicate
146+
const deletedFn = db.deleteWhere(item => (item.age as number) < 18)
120147
```
121148

122149
### `db.clear()`
123150

124151
Clear all records (writes empty array to file).
125152

126153
```typescript
154+
// Remove all records
155+
// Note: Also persists empty array to file
127156
db.clear()
128157
```
129158

@@ -132,6 +161,8 @@ db.clear()
132161
Reload internal data from file.
133162

134163
```typescript
164+
// Reload data from file
165+
// Useful when file is modified externally
135166
db.reload()
136167
```
137168

@@ -142,15 +173,36 @@ db.reload()
142173
Create a query builder. `condition` can be a string condition or a predicate function.
143174

144175
```typescript
176+
// Query with string condition
145177
const qb = db.where('age >= 18')
178+
179+
// Query with function predicate
146180
const qbFn = db.where(item => (item.age as number) >= 18)
147181
```
148182

183+
### Chaining `where()`
184+
185+
You can chain multiple `where()` calls to refine your query:
186+
187+
```typescript
188+
// Chain multiple where conditions (AND logic)
189+
db.where('age >= 18').where('profile.active = true').get()
190+
191+
// Mix string conditions with function predicates
192+
db.where('age >= 18')
193+
.where(item => (item.name as string).startsWith('J'))
194+
.first()
195+
196+
// Chaining works with all query builder methods
197+
db.where('age >= 18').where('profile.role = admin').count()
198+
```
199+
149200
### `where(...).get()`
150201

151202
Get all matching records (copy).
152203

153204
```typescript
205+
// Get all matching records
154206
const adults = db.where('age >= 18').get()
155207
```
156208

@@ -159,6 +211,7 @@ const adults = db.where('age >= 18').get()
159211
Get the first matching record or `null`.
160212

161213
```typescript
214+
// Get first match or null if none found
162215
const first = db.where('profile.role = admin').first()
163216
```
164217

@@ -167,6 +220,7 @@ const first = db.where('profile.role = admin').first()
167220
Count matching records.
168221

169222
```typescript
223+
// Count matching records
170224
const count = db.where('profile.active = true').count()
171225
```
172226

@@ -175,7 +229,10 @@ const count = db.where('profile.active = true').count()
175229
Update all matching records (writes through to the database file when called from `db.where(...)`).
176230

177231
```typescript
232+
// Update all matching records
178233
db.where('profile.role = admin').update({ level: 'staff' })
234+
235+
// Update nested properties
179236
db.where('profile.role = admin').update({ 'profile.verified': true })
180237
```
181238

@@ -184,6 +241,7 @@ db.where('profile.role = admin').update({ 'profile.verified': true })
184241
Delete all matching records (writes through to the database file when called from `db.where(...)`).
185242

186243
```typescript
244+
// Delete all matching records
187245
const deleted = db.where('age < 18').delete()
188246
```
189247

build.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export default defineBuildConfig({
1414
clean: true,
1515
/** Path alias for imports (e.g. @root → src). */
1616
alias: {
17-
'@app': resolve(__dirname, 'src')
17+
'@app': resolve(__dirname, 'src'),
18+
'@core': resolve(__dirname, 'src', 'core'),
19+
'@query': resolve(__dirname, 'src', 'query')
1820
},
1921
/** Rollup options: emit CJS and inline runtime deps. */
2022
rollup: {

deno.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767
"imports": {
6868
"@std/assert": "jsr:@std/assert@^1.0.19",
6969
"@neabyte/jsonary": "./src/index.ts",
70-
"@app/": "./src/"
70+
"@app/": "./src/",
71+
"@core/": "./src/core/",
72+
"@query/": "./src/query/",
73+
"@tests/": "./tests/"
7174
},
7275
"publish": {
7376
"include": ["src/", "README.md", "LICENSE", "USAGE.md", "deno.json"]

0 commit comments

Comments
 (0)