borogove
created pr with
borogove/sqlite-injectable-driver.1
commented
Changes are available at https://tangled.org/mrry.band/borogove on branch sqlite-injectable-driver.
added borogove/sqlite-injectable-driver.2
1: 981fe7d = 1: 981fe7d Use arrays
2: ef9e639 = 2: ef9e639 Make prepare public, remove formatParam and first
3: f949361 ! 3: a97c836 Allow injectable drivers for Sqlite
commented
browser tests dont pass
added borogove/sqlite-injectable-driver.3
1: 981fe7d = 1: 981fe7d Use arrays
2: ef9e639 ! 2: 11eb826 Make prepare public, remove formatParam and first
3: a97c836 ! 3: 34cee7d Allow injectable drivers for Sqlite
cmds
checkout latest patchset:
ssh pr.pico.sh pull borogove:sqlite-injectable-driver | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull borogove:sqlite-injectable-driver [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh borogove:sqlite-injectable-driveradd comment to patch request:
ssh pr.pico.sh comment borogove:sqlite-injectable-driver "lgtm!"
Patchset
borogove/sqlite-injectable-driver.3
Make prepare public, remove formatParam and first
Eric Roberts
2026-11-09T19:29:48ZWe were shifting off the first query because that's all the bind would apply to, but then we were formatting the params there. We have a general purpose prepare we can use, so we can delete formatParam and stop treating the first query like a special case. This change did necessitate updating test expecations. Haxe's bytes.ofdata mutates the original arraybuffer to add two properties. Our tests then think they don't equal each other even though they do in practice. Makes prepare public so the injectable driver that I'm making for Tauri can use it.
Semantic diff summary
0 added,
2 modified,
0 signature changed,
0 removed
across 1 analyzed file
(2 files skipped: unsupported file type)
+1
-2
borogove/persistence/Sqlite.hx
#
| ... | ... | @@ -44,8 +44,7 @@ class Sqlite implements Persistence implements KeyValueStore { | |
| 44 | 44 | final media: MediaStore; | |
| 45 | 45 | final storeMessagesSerialized = new AsyncLock(); | |
| 46 | 46 | ||
| 47 | - | @:allow(borogove) | |
| 48 | - | private static function prepare(q: { sql: String, ?params: Array<Dynamic> }): String { | |
| 47 | + | public static function prepare(q: { sql: String, ?params: Array<Dynamic> }): String { | |
| 49 | 48 | return ~/\?/gm.map(q.sql, f -> { | |
| 50 | 49 | var p = (q.params ?? []).shift(); | |
| 51 | 50 | return switch (Type.typeof(p)) { |
+1
-13
borogove/persistence/SqliteDriver.js.hx
#
| ... | ... | @@ -145,15 +145,13 @@ class SqliteDriver { | |
| 145 | 145 | } | |
| 146 | 146 | ||
| 147 | 147 | private function execute(qs: Array<{ sql: String, ?params: Array<Dynamic> }>): Promise<Array<Dynamic>> { | |
| 148 | - | final first = qs.shift(); | |
| 149 | 148 | final sql = qs.map(q -> Sqlite.prepare(q) + ";"); | |
| 150 | 149 | final items: Array<Dynamic> = []; | |
| 151 | 150 | var signalAllDone; | |
| 152 | 151 | final allDone = new Promise((resolve, reject) -> signalAllDone = resolve); | |
| 153 | 152 | return sqlite('exec', { | |
| 154 | 153 | dbId: dbId, | |
| 155 | - | sql: [first.sql + ";"].concat(sql), | |
| 156 | - | bind: (first.params ?? []).map(formatParam), | |
| 154 | + | sql: sql, | |
| 157 | 155 | rowMode: "object", | |
| 158 | 156 | callback: (r) -> { | |
| 159 | 157 | if (r.rowNumber == null) { |
| ... | ... | @@ -177,15 +175,5 @@ class SqliteDriver { | |
| 177 | 175 | public function exec(sql: String, ?params: Array<Dynamic>) { | |
| 178 | 176 | return execMany([{ sql: sql, params: params }]); | |
| 179 | 177 | } | |
| 180 | - | ||
| 181 | - | private function formatParam(p: Dynamic): Dynamic { | |
| 182 | - | return switch (Type.typeof(p)) { | |
| 183 | - | case TClass(haxe.io.Bytes): | |
| 184 | - | var bytes:Bytes = cast p; | |
| 185 | - | return bytes.getData(); | |
| 186 | - | case _: | |
| 187 | - | return p; | |
| 188 | - | } | |
| 189 | - | } | |
| 190 | 178 | } | |
| 191 | 179 | #end |
+8
-3
test/persistence-tests.ts
#
| ... | ... | @@ -1937,7 +1937,12 @@ export function sharedPersistenceTests(test) { | |
| 1937 | 1937 | ); | |
| 1938 | 1938 | } | |
| 1939 | 1939 | const loaded = await persistence.getOmemoPreKeys(identifier); | |
| 1940 | - | expect(loaded).toEqual(preKeys); | |
| 1940 | + | expect(loaded).toHaveLength(preKeys.length); | |
| 1941 | + | const loadedById = new Map(loaded.map((key) => [key.keyId, key])); | |
| 1942 | + | for (const preKey of preKeys) { | |
| 1943 | + | const actual = loadedById.get(preKey.keyId); | |
| 1944 | + | expectKeyPair(actual.keyPair, preKey.keyPair); | |
| 1945 | + | } | |
| 1941 | 1946 | }); | |
| 1942 | 1947 | ||
| 1943 | 1948 | test("storeOmemoSignedPreKey and getOmemoSignedPreKey", async ({ |
| ... | ... | @@ -2003,7 +2008,7 @@ export function sharedPersistenceTests(test) { | |
| 2003 | 2008 | account, | |
| 2004 | 2009 | address, | |
| 2005 | 2010 | ); | |
| 2006 | - | expect(loaded).toEqual(identityKey); | |
| 2011 | + | expectKey(loaded, identityKey); | |
| 2007 | 2012 | }); | |
| 2008 | 2013 | ||
| 2009 | 2014 | test("getOmemoSession returns null when none is stored", async ({ |
| ... | ... | @@ -2314,5 +2319,5 @@ function expectKeyPair(actual: TestKeyPair, expected: TestKeyPair) { | |
| 2314 | 2319 | } | |
| 2315 | 2320 | ||
| 2316 | 2321 | function expectKey(actual: ArrayBuffer, expected: ArrayBuffer) { | |
| 2317 | - | expect(actual).toEqual(expected); | |
| 2322 | + | expect(new Uint8Array(actual)).toEqual(new Uint8Array(expected)); | |
| 2318 | 2323 | } |