Skip to content

Commit

Permalink
Repaired the sqlx driver from selecting out of order columns
Browse files Browse the repository at this point in the history
  • Loading branch information
tachyonicbytes committed Oct 26, 2023
1 parent 3f0bd42 commit 011f9bb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions clients/typescript/src/drivers/sqlx/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class DatabaseAdapter implements DatabaseAdapterInterface {
// It is only meant to be used within transactions.
async _queryUncoordinated(stmt: Statement): Promise<Row[]> {
const res = await this.db.exec(stmt)
console.log("YYYYYYY: ", res)
return resultToRows([res])
}

Expand Down
10 changes: 7 additions & 3 deletions clients/typescript/src/drivers/sqlx/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class ElectricDatabase implements Database {

async tauri_exec(statement: Statement): Promise<QueryExecResult> {
let [keys, values] = separateBindParams(statement.args)
return await this.invoke("tauri_exec_command", { sql: statement.sql, bind_params: { keys, values } });
let result = await this.invoke("tauri_exec_command", { sql: statement.sql, bind_params: { keys, values } })
console.log("YYYYYYYY: ", result)
return result
}

async exec(statement: Statement): Promise<QueryExecResult> {
Expand All @@ -47,7 +49,7 @@ export class ElectricDatabase implements Database {
}

this.rowsModified = result.rows_modified
let rows: Array<Object> = JSON.parse(result.result)
let rows: Array<{ [key: string]: any }> = JSON.parse(result.result)

try {
const values: SqlValue[][] = []
Expand All @@ -58,7 +60,9 @@ export class ElectricDatabase implements Database {
}

rows.forEach((row) => {
let vals = Object.values(row)
// let vals = Object.values(row)
let vals = keys.map(key => row[key])

for (let i = 0; i < vals.length; i++) {
if (vals[i][0] == "\u0000") {
vals[i] = (vals[i].charCodeAt(1) * 2 ** 32 + vals[i].charCodeAt(2) * 2 ** 16 + vals[i].charCodeAt(3) * 1)
Expand Down
4 changes: 4 additions & 0 deletions clients/typescript/src/satellite/oplog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ export const toTransactions = (
if (opLogEntries.length == 0) {
return []
}
console.log("YYYY", opLogEntries)
console.log("YYYY", relations)

const to_commit_timestamp = (timestamp: string): Long =>
Long.UZERO.add(new Date(timestamp).getTime())
Expand Down Expand Up @@ -373,8 +375,10 @@ export const opLogEntryToChange = (
}

console.log("record: ", record)
console.log("entry.oldRow: ", entry.oldRow)
if (entry.oldRow != null) {
oldRecord = JSON.parse(entry.oldRow)
// oldRecord = entry.oldRow
}
console.log("oldRecord: ", oldRecord)
const relation = relations[`${entry.tablename}`]
Expand Down
2 changes: 2 additions & 0 deletions clients/typescript/src/satellite/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ export class SatelliteProcess implements Satellite {
}

async _replicateSnapshotChanges(results: OplogEntry[]): Promise<void> {
console.log("YYYYY: ", results)
// TODO: Don't try replicating when outbound is inactive
if (this.client.isClosed()) {
return
Expand Down Expand Up @@ -1066,6 +1067,7 @@ export class SatelliteProcess implements Satellite {
ORDER BY rowid ASC
`
const rows = await this.adapter.query({ sql: selectEntries, args: [since] })
console.log("YYYYYY: ", rows)
return rows as unknown as OplogEntry[]
}

Expand Down

0 comments on commit 011f9bb

Please sign in to comment.