Skip to content
Draft

wip #195

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
537 commits
Select commit Hold shift + click to select a range
4529cc7
Pass fixed length hint to selva for string & bin
OlliV Feb 12, 2026
7daaf41
Add todo comments
OlliV Feb 12, 2026
8e473d6
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 13, 2026
092b1a3
fix
jimdebeer Feb 13, 2026
e167ae7
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 13, 2026
69874e0
wip
youzi Feb 13, 2026
435a4ff
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 13, 2026
049659c
fix
jimdebeer Feb 13, 2026
776a3cf
Minor opt for mempool_new_slab()
OlliV Feb 13, 2026
0cd6188
Inline selva_foreach_block() when possible
OlliV Feb 13, 2026
010ff0d
add filter ast creation
youzi Feb 13, 2026
8cf85f2
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 13, 2026
1e5b845
add isolated query()
youzi Feb 13, 2026
4d8b879
update query()
youzi Feb 13, 2026
06fc85f
ast building for aggregate
youzi Feb 13, 2026
e9e7ff8
Prealloc mempool slabs before loading nodes
OlliV Feb 13, 2026
c0ffa36
Disable pool prealloc for now
OlliV Feb 13, 2026
9ea8a0c
add includes (step 1)
jimdebeer Feb 13, 2026
d263178
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 13, 2026
e54de6e
add aggregate support to new query and rename harmonicMean to hmean
youzi Feb 13, 2026
a033512
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 13, 2026
cd3ca48
add .range
youzi Feb 13, 2026
874e029
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 13, 2026
57b3541
init sort
youzi Feb 13, 2026
796b705
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 13, 2026
e06a801
add tests for validation
youzi Feb 13, 2026
90580d4
remove whtsp
OlliV Feb 13, 2026
bcc32df
Try init mempool while loading nodes
OlliV Feb 13, 2026
a029737
Revert "Try init mempool while loading nodes"
OlliV Feb 13, 2026
2f881e5
Prealloc nodepool only makes partials harder
OlliV Feb 13, 2026
8f83638
Add more type testing
OlliV Feb 13, 2026
d5ed08a
update typeDef and add required
youzi Feb 13, 2026
a1612ab
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 13, 2026
1ffec1e
required validation
youzi Feb 13, 2026
f44f56a
add test for delete
youzi Feb 13, 2026
902fcae
wip
youzi Feb 13, 2026
5cd630d
edge refs
youzi Feb 13, 2026
6096b2f
update types
youzi Feb 13, 2026
3cc77ee
wip
youzi Feb 13, 2026
68fd4fb
init hooks
youzi Feb 13, 2026
5f5c8d2
wip
youzi Feb 13, 2026
a940bda
add hooks
youzi Feb 14, 2026
a491c2e
clean up condition parsing
jimdebeer Feb 14, 2026
29853a2
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 14, 2026
11fee38
fix
jimdebeer Feb 14, 2026
5d5064b
fixie
youzi Feb 14, 2026
1cd5289
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 14, 2026
07b8b3e
Add dependent test case
OlliV Feb 16, 2026
90bbd8d
exports
jimdebeer Feb 16, 2026
a081414
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 16, 2026
8324a56
edge filter start
jimdebeer Feb 16, 2026
0ebd2e6
very ugly fix to be cleaned
maovieira Feb 16, 2026
adb02cc
moving parameters to aggContext
maovieira Feb 16, 2026
35b4bd1
Code cleanup
OlliV Feb 16, 2026
a988c85
Test circular dependency
OlliV Feb 16, 2026
c85ec41
db -> client
OlliV Feb 17, 2026
15b3e40
Simplify & fix
OlliV Feb 17, 2026
6822e8d
prettier
OlliV Feb 17, 2026
d45268f
db -> client
OlliV Feb 17, 2026
6b02243
Minimum maxModifySize is now 256
OlliV Feb 17, 2026
c891584
Add some jsdoc
OlliV Feb 17, 2026
95623c0
selva.c shouldn't typically be used directly
OlliV Feb 17, 2026
812e2d2
Don't trigger dependent check when refs is cleared
OlliV Feb 17, 2026
de31950
remove old modify files
youzi Feb 17, 2026
fb6ffcb
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 17, 2026
e93ff88
Remove commented out code
OlliV Feb 17, 2026
d6043ab
Add hook to dirty marking
OlliV Feb 17, 2026
a508428
doc
OlliV Feb 17, 2026
4b680af
dirty hook needs ctx
OlliV Feb 17, 2026
e17987c
add expire
youzi Feb 17, 2026
a03137d
basic test is back
maovieira Feb 17, 2026
7b5bf80
fixing/uncommenting mostly agg tests
maovieira Feb 17, 2026
7c9ed85
Merge branch 'aggContext' into modify
maovieira Feb 17, 2026
cf39fc3
Move type
OlliV Feb 18, 2026
c8b2355
No dirty ranges in zig
OlliV Feb 18, 2026
05d1c1d
dead code
OlliV Feb 18, 2026
e9add24
Remove unnecessary selva.markDirty() calls
OlliV Feb 18, 2026
e6570ce
Add sort
jimdebeer Feb 18, 2026
5cb6890
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 18, 2026
3a9c1b6
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 18, 2026
f21238f
add sort
jimdebeer Feb 18, 2026
4f3a42a
remove logs
jimdebeer Feb 18, 2026
0d1ae07
nested filter in refs
jimdebeer Feb 18, 2026
8dc6a84
typed DbClient
youzi Feb 18, 2026
734bfa8
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 18, 2026
42d899c
update tests
youzi Feb 18, 2026
f975b98
Cleanup save test
OlliV Feb 18, 2026
d1f62f8
fix DESC references iterator
jimdebeer Feb 18, 2026
325b396
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 18, 2026
6a9d452
more types
youzi Feb 18, 2026
4935528
sort on edge
jimdebeer Feb 18, 2026
d84bfab
more types
youzi Feb 18, 2026
435aecf
more aggregate query types
youzi Feb 18, 2026
afe983f
fix
jimdebeer Feb 18, 2026
d152e61
edge include
jimdebeer Feb 18, 2026
db0fb6f
filter
jimdebeer Feb 18, 2026
615131c
fix
jimdebeer Feb 18, 2026
6a60dfb
Use auto
OlliV Feb 18, 2026
321ec7c
No O_SEARCH on Linux
OlliV Feb 18, 2026
e8608cb
More comments about counted_by
OlliV Feb 18, 2026
d4df355
The compiler may not have reproducible attr
OlliV Feb 18, 2026
1456cf2
Bump to gcc 15.2
OlliV Feb 18, 2026
2cc73bb
Wrong type
OlliV Feb 18, 2026
4807e6c
fix ver check
OlliV Feb 18, 2026
c0f90b1
Fix db inline functions on gcc
OlliV Feb 18, 2026
29b6676
No O_RESOLVE_BENEATH on Linux
OlliV Feb 18, 2026
e6d9ae8
Use auto to infer types in C
OlliV Feb 18, 2026
b5bcaaa
Mute gcc bug with auto
OlliV Feb 18, 2026
e517638
reproducible now works
OlliV Feb 18, 2026
eb28438
More nice type inferrence
OlliV Feb 18, 2026
3850df8
add iterator
jimdebeer Feb 18, 2026
b6fb994
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 18, 2026
92ed603
perf
jimdebeer Feb 18, 2026
8b029a8
x
jimdebeer Feb 18, 2026
d9ba435
Infer type
OlliV Feb 19, 2026
ffc9ee0
Improve logging
OlliV Feb 19, 2026
c1b57ff
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 19, 2026
7e45923
Crash on load error and don't log ENOENT
OlliV Feb 19, 2026
e3f2950
wip
youzi Feb 19, 2026
b161ffb
Even better logs
OlliV Feb 19, 2026
57008ec
Don't hash aliases with blocks
OlliV Feb 19, 2026
8777315
This function must be static inline
OlliV Feb 19, 2026
c7a84eb
Separate declaration and definition
OlliV Feb 19, 2026
553ddef
More auto just for fun
OlliV Feb 19, 2026
004ebc4
cardinality functions on refereces
maovieira Feb 19, 2026
cc257fb
fix display cardinality style
maovieira Feb 19, 2026
a7eb6fb
fix default precision cardinality test
maovieira Feb 19, 2026
d06cc73
This inline function needs a stupid macro helper
OlliV Feb 19, 2026
39a6cff
Improve SelvaFieldSchema packing and handling
OlliV Feb 19, 2026
a79da5f
lt x leq test
maovieira Feb 19, 2026
492ba9b
Merge branch 'modify' of github.com:atelier-saulx/based into modify
maovieira Feb 19, 2026
5cf6f82
fix
jimdebeer Feb 19, 2026
90eab79
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 19, 2026
9a2b0ac
Vector type fixes
OlliV Feb 19, 2026
0edde6d
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 19, 2026
e28c6ed
finishing agg references filter
maovieira Feb 19, 2026
95d7561
Wrong size for float32 vectors
OlliV Feb 20, 2026
009898e
Cleanup vector schema
OlliV Feb 20, 2026
ef818c5
Only accept the selected type for vectors
OlliV Feb 20, 2026
ede73b5
prettier
OlliV Feb 20, 2026
26540ef
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 20, 2026
108d633
Wrong increment
OlliV Feb 20, 2026
e352aef
Fix vector test
OlliV Feb 20, 2026
545a905
Test vector on edge
OlliV Feb 20, 2026
97ef4c2
Common validate
OlliV Feb 20, 2026
85a24ec
Fix set/clear colvec on modify
OlliV Feb 20, 2026
e5c1454
More nice typing
OlliV Feb 20, 2026
9ab7ade
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 20, 2026
69d626d
defaults for vectors
OlliV Feb 20, 2026
e5e9aef
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 20, 2026
f878a50
vector validation
youzi Feb 20, 2026
affc264
Handle empty smb field
OlliV Feb 20, 2026
9736b37
Default value handling for vector
OlliV Feb 20, 2026
fbae3e2
more filter
jimdebeer Feb 23, 2026
67c694f
start of edge only filter
jimdebeer Feb 23, 2026
42c4db3
split multiple
jimdebeer Feb 23, 2026
7caf869
more fix
jimdebeer Feb 23, 2026
cb0cdb5
update exports
jimdebeer Feb 23, 2026
5cf4b77
colvec default
OlliV Feb 23, 2026
70030f8
more enums
jimdebeer Feb 23, 2026
83ec510
Merge branch 'modify' of github.com:atelier-saulx/based into modify
jimdebeer Feb 23, 2026
1b4b3b0
add logs, clean up
jimdebeer Feb 23, 2026
f9e4fcd
perf test
jimdebeer Feb 23, 2026
5acca2e
fix problem with edge
jimdebeer Feb 23, 2026
34d03bd
spec -> head in schema
OlliV Feb 23, 2026
d382131
Use packed struct for the schema hdr
OlliV Feb 23, 2026
a95f945
prettier
OlliV Feb 23, 2026
99bbb5a
Fix save test
OlliV Feb 23, 2026
e904ac1
Use DbClient
OlliV Feb 23, 2026
4b640cd
Use DbClient
OlliV Feb 23, 2026
554b7e2
Use DbClient
OlliV Feb 23, 2026
7d1fe18
aggregates test
youzi Feb 23, 2026
e4f5740
update test
youzi Feb 23, 2026
a7df7d5
update
youzi Feb 23, 2026
1803dba
port aggregate tests
youzi Feb 23, 2026
89b3f80
port alias test
youzi Feb 23, 2026
9e2a7f4
Merge branch 'modify' of github.com:atelier-saulx/based into modify
maovieira Feb 23, 2026
aa1ad90
update
youzi Feb 23, 2026
76b9f08
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 23, 2026
8225226
fix top level count selection
maovieira Feb 23, 2026
206942e
fix top level count test
maovieira Feb 23, 2026
98277c0
fix variance population in AST
maovieira Feb 23, 2026
f77c950
fix numeric types agg test
maovieira Feb 23, 2026
5a1a101
Incorrect typing for TypedArray
OlliV Feb 24, 2026
50f80b3
Remove unused imports
OlliV Feb 24, 2026
cbbde9a
Only one type for TypedArray
OlliV Feb 24, 2026
d27f8e9
wip
youzi Feb 24, 2026
0ed6fd8
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 24, 2026
67aef2c
covec test fixes
OlliV Feb 24, 2026
a4ad927
backup test with testDb
OlliV Feb 24, 2026
6c3d236
use testDb
OlliV Feb 24, 2026
167136a
wip
youzi Feb 24, 2026
9e217ae
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 24, 2026
bf362d3
new testDb and query2
OlliV Feb 24, 2026
b7a7827
Too long vectors are no longer truncated
OlliV Feb 24, 2026
ecf71d5
Handle interrupted type creat properly
OlliV Feb 24, 2026
f466c21
Use testDb
OlliV Feb 24, 2026
b04a502
fix sized string check
maovieira Feb 24, 2026
cd3ee03
dev
maovieira Feb 24, 2026
93ec7f0
Merge branch 'modify' of github.com:atelier-saulx/based into modify
maovieira Feb 24, 2026
1e20cd7
testDb and query2
OlliV Feb 24, 2026
1ceb199
Merge branch 'modify' of github.com:atelier-saulx/based into modify
maovieira Feb 24, 2026
8120e17
Unused var
OlliV Feb 24, 2026
775d7f9
More explicit schema is required now
OlliV Feb 24, 2026
1d5f26b
Add noClean opt to testDb
OlliV Feb 24, 2026
5c08c6d
Test cleanup
OlliV Feb 24, 2026
cbdd4bf
Test cleanup
OlliV Feb 24, 2026
ce68b30
prettier
OlliV Feb 24, 2026
d2836e4
Test cleanup
OlliV Feb 24, 2026
998c795
Test cleanup
OlliV Feb 24, 2026
0f944eb
Test cleanup
OlliV Feb 24, 2026
0000e47
Test cleanup
OlliV Feb 24, 2026
bb70f6e
wip
youzi Feb 24, 2026
fa191a4
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 24, 2026
91a56a8
replace query with query2
youzi Feb 24, 2026
119bfaf
Northwind fix
OlliV Feb 24, 2026
0f28f3d
update types
youzi Feb 24, 2026
49f8340
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 24, 2026
138fc6f
wip
youzi Feb 24, 2026
2d0dab0
wip
youzi Feb 24, 2026
831ade1
better types for edge refs
youzi Feb 24, 2026
72bfead
wip
youzi Feb 24, 2026
b7ac650
range in group by. keys
maovieira Feb 24, 2026
6fa950e
Merge branch 'modify' of github.com:atelier-saulx/based into modify
maovieira Feb 24, 2026
4cee1a4
test range group by key
maovieira Feb 24, 2026
91c73e9
aggregate tests in place again
maovieira Feb 24, 2026
fd4aec5
Use the new testDb
OlliV Feb 25, 2026
f06515e
Use the new testDb
OlliV Feb 25, 2026
a88e920
Use the new testDb
OlliV Feb 25, 2026
0d0e366
Remove mixed test
OlliV Feb 25, 2026
a770656
Use the new testDb
OlliV Feb 25, 2026
6e58cbf
Merge branch 'modify' of github.com:atelier-saulx/based into modify
youzi Feb 25, 2026
f3e628e
Allow passing db path
OlliV Feb 25, 2026
5d62139
Use the new client
OlliV Feb 25, 2026
749b335
Use testDb
OlliV Feb 25, 2026
3472f03
Use the new client
OlliV Feb 25, 2026
d651dc9
this must be final
OlliV Feb 25, 2026
afbfb03
Use the new client
OlliV Feb 25, 2026
ad0ff5e
Fix upserts
OlliV Feb 25, 2026
bc926c5
fix nyctaxi
OlliV Feb 25, 2026
9b98c8b
testdb fixes
OlliV Feb 25, 2026
b61ab56
Use testDb
OlliV Feb 25, 2026
04b92b3
Remove dead code
OlliV Feb 25, 2026
267073a
Use testDb
OlliV Feb 25, 2026
9cbe4dd
update types
youzi Feb 25, 2026
87ea066
add .locale
youzi Feb 25, 2026
458c093
Remove old TODO comment
OlliV Feb 26, 2026
2bede7c
The constraint is constant
OlliV Feb 26, 2026
56afac4
Tail insertion is expected by default
OlliV Feb 26, 2026
6af05f8
New checksum fun
OlliV Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 11 additions & 20 deletions GEMINI.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,14 @@ const a = (ctx) => {
- Prefer self-documenting code (clear variable names, etc.).
- If you must add a comment, keep it minimal and explain the _why_, not the _what_.

## Running db Tests
## Running Tests

The following instructions apply only to the `@based/db` package. Other packages have their own test runners.
The project uses a custom test runner. **Always use `npm test`** to run tests. Do **NOT** use `npx tsx` or `node` directly on test files.

The `db` package uses a custom test runner. To run the tests, you can use `npm run test` from the `packages/db` directory, or `npm run test -w @based/db` from the root of the project. You can pass arguments to filter the tests.
You can run tests from the root simply with `npm test`. You can pass arguments to filter the tests.

```bash
# From packages/db
npm run test -- [filters]

# From root
npm run test -w @based/db -- [filters]
npm test [filter]
```

There is also a `test-fast` script that skips the build step.
Expand All @@ -111,28 +107,23 @@ You can filter which tests to run by providing one or more filter arguments.

- **Run all tests:**
```bash
# from packages/db
npm run test
npm test
```
- **Run all tests and stop on the first failure:**
- **Run tests for a specific file or folder (e.g. `query/ast`):**
```bash
# from packages/db
npm run test -- stopOnFail
npm test query/ast
```
- **Run tests in files with "view" in the path:**
- **Run all tests and stop on the first failure:**
```bash
# from packages/db
npm run test -- view
npm test stopOnFail
```
- **Run tests with "observe" in the name, in files with "view" in the path:**
```bash
# from packages/db
npm run test -- view:observe
npm test view:observe
```
- **Run all tests 10 times:**
```bash
# from packages/db
npm run test -- 10
npm test 10
```

## Zig version
Expand Down
19 changes: 9 additions & 10 deletions src/db-client/modify/Ctx.ts → _modify/Ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const MODIFY_HEADER_SIZE = 1 + 4 + 8 + 4
export class Ctx {
constructor(schemaChecksum: number, buf: Uint8Array<ArrayBufferLike>) {
this.buf = buf
buf[4] = OpType.modify // make enum later 1 means normal MODIFY
buf[4] = OpType.modify
writeUint64(buf, schemaChecksum, 5)
this.reset()
}
Expand All @@ -19,18 +19,18 @@ export class Ctx {
this.cursor = {}
this.batch = {}
}
start: number
index: number
schema: SchemaTypeDef
start!: number
index!: number
schema!: SchemaTypeDef
buf: Uint8Array<ArrayBufferLike>
max: number
size: number
max!: number
size!: number
unsafe?: boolean
operation: ModOpEnum
operation!: ModOpEnum
main: Map<PropDef, any> = new Map()
draining: Promise<void>
draining!: Promise<void>
scheduled: Promise<void> | undefined
locale: LangCodeEnum
locale!: LangCodeEnum
sort: number = 0
sortText: number = 0
defaults: number = 0
Expand All @@ -39,7 +39,6 @@ export class Ctx {
prop?: number
main?: number
operation?: ModOpEnum
upserting?: boolean
} = {}
batch: {
count?: number
Expand Down
6 changes: 3 additions & 3 deletions src/db-client/modify/Tmp.ts → _modify/Tmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class Tmp implements Promise<number> {
this.batch = ctx.batch
this.tmpId = ctx.batch.count++
}
[Symbol.toStringTag]: 'ModifyPromise'
[Symbol.toStringTag]!: 'ModifyPromise'
#schema: SchemaTypeDef
#id: number
#err: number
#id!: number
#err!: number
get error(): Error | undefined {
if (this.batch.ready && !this.id) {
if (this.#err in errorMap) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import type { Ctx } from '../Ctx.js'
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js'
import { reserve } from '../resize.js'
import { writeU32, writeU8 } from '../uint.js'
import { writeObject } from './object.js'

type Edges = Record<string, any> | undefined
const getEdges = (obj: Record<string, any>): Edges => {
let edges: Edges
for (const i in obj) {
if (i[0] === '$' && i !== '$index') {
edges ??= {}
edges[i] = obj[i]
}
}
return edges
}

export const writeReferences = (ctx: Ctx, def: PropDef, val: any) => {
if (typeof val !== 'object') {
Expand All @@ -27,40 +40,51 @@ export const writeReferences = (ctx: Ctx, def: PropDef, val: any) => {
writeU8(ctx, RefOp.clear)
}

let op: RefOpEnum | undefined
let prevOp: RefOpEnum | undefined
let pos = 0
let len = 0

for (const item of val) {
let id: number
let nextOp: RefOpEnum
let op: RefOpEnum
let edges: Edges
if (typeof item === 'number') {
id = item
nextOp = RefOp.set
op = RefOp.set
} else if (typeof item === 'object' && item !== null && item.id) {
id = item.id
nextOp = RefOp.set
edges = getEdges(item)
if (edges) {
op = RefOp.setEdge
} else {
op = RefOp.set
}
} else {
// not handled yet
throw new Error('references payload, not handled yet - wip')
}

if (op !== nextOp!) {
if (op) {
if (prevOp !== op!) {
if (prevOp) {
// write previous len
writeUint32(ctx.buf, len * 4, pos)
}
writeU8(ctx, (op = nextOp!))
writeU8(ctx, (prevOp = op!))
pos = ctx.index
len = 0
ctx.index += 4
}

writeU32(ctx, id)
if (edges) {
writeObject(ctx, def.edges as any, edges)
writeU8(ctx, ModOp.end)
}

len++
}

writeUint32(ctx.buf, len * 4, pos)
writeUint32(ctx.buf, len, pos)
writeU8(ctx, RefOp.end)
return
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions _modify/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { LangCode, ModOp } from '../../zigTsExports.js'

export const RANGE_ERR = 1
export const MOD_OPS_TO_STRING = {
[ModOp.createProp]: 'create',
[ModOp.updateProp]: 'update',
[ModOp.increment]: 'update',
[ModOp.expire]: 'update',
} as const

export const enum SIZE {
DEFAULT_CURSOR = 11,
}

export type ModifyOpts = {
unsafe?: boolean
locale?: keyof typeof LangCode
}

export const NOEDGE_NOINDEX_REALID = 0
export const EDGE_NOINDEX_REALID = 1
export const EDGE_INDEX_REALID = 2
export const NOEDGE_INDEX_REALID = 3
export const NOEDGE_NOINDEX_TMPID = 4
export const EDGE_NOINDEX_TMPID = 5
export const EDGE_INDEX_TMPID = 6
export const NOEDGE_INDEX_TMPID = 7

// export const REF_OP_OVERWRITE = 0
// export const REF_OP_UPDATE = 1
// export const REF_OP_DELETE = 2
// export const REF_OP_PUT_OVERWRITE = 3
// export const REF_OP_PUT_ADD = 4

// export type RefOp = typeof REF_OP_OVERWRITE | typeof REF_OP_UPDATE
File renamed without changes.
69 changes: 69 additions & 0 deletions src/db-client/modify/update/index.ts → _modify/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,72 @@ export function update(
return handleError(db, ctx, update, arguments, e)
}
}

// const simpleUpdate = () => {

// }

/*
CREATE

article {
body: 'xxx',
age: 10,
rating: 4
}

==>

create|article|main:10,4|body:xxx

UPDATE

article 10 {
body: 'xxx',
age: 10,
rating: 4
}

==>

update|article|id:10|main:0:10|main:1:4|body:xxx

update(u8)|size(u32)|type(u8)|id(u32)|...[prop(u8)]


propType,size,value
// age:number:81
1,4,81



name,string,value


UPSERT

article 'abc', {
body: 'xxx',
age: 10,
rating: 4
}

==>

upsert|article|abc|main:0:10|main:1:4|body:xxx









--------------------------------------------------------------------





*/
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions clibs/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ endif

ifeq ($(uname_S),Linux)
CFLAGS += -g -ggdb3 -fno-math-errno -ftree-vectorize -Wstrict-aliasing=3
# Mute the gcc bug when `auto` is used to infer the type
CFLAGS += -Wno-old-style-declaration
#CFLAGS += -opt-info-vec-optimized
#CFLAGS += -ftree-vectorizer-verbose=5 -fopt-info-vec-missed

Expand Down
10 changes: 7 additions & 3 deletions clibs/include/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@
* unsigned int len;
* char buf[] __counted_by(len);
* };
* __builtin_dynamic_object_size(p->buf) == p->len * sizeof(*p->buf)
* *__builtin_counted_by_ref(p->puf) = len;
* __builtin_dynamic_object_size(p->buf) == p->len * sizeof(*p->buf);
*/
#define __counted_by(member) __attribute__((__counted_by__(member)))
#else
Expand All @@ -213,13 +214,16 @@
#endif

#ifndef __pcounted_by
#if __has_attribute(__counted_by__) && !defined(__clang__)
#if __has_attribute(__counted_by__) && \
!defined(__clang__) && \
(__GNUC__ > 15 || (__GNUC__ == 14 && __GNUC_MINOR__ > 2))
/**
* struct foo {
* unsigned int len;
* char *buf __pcounted_by(len);
* };
* __builtin_dynamic_object_size(p->buf) == p->len * sizeof(*p->buf)
* *__builtin_counted_by_ref(p->puf) = len;
* __builtin_dynamic_object_size(p->buf) == p->len * sizeof(*p->buf);
*/
#define __pcounted_by(member) __attribute__((__counted_by__(member)))
#else
Expand Down
3 changes: 3 additions & 0 deletions clibs/include/selva/colvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@ void *colvec_get_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct
SELVA_EXPORT
void colvec_set_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs, const void *vec);

SELVA_EXPORT
void colvec_clear_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs);

SELVA_EXPORT
int colvec_foreach(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs, node_id_t start, uint32_t len, void (*cb)(node_id_t node_id, void *vec, void *arg), void *arg);
Loading