Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/plugin-client-drizzle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"scripts": {
"build": "rimraf dist && rollup -c",
"tsc": "tsc --noEmit"
"tsc": "tsc --noEmit",
"test": "NODE_OPTIONS='--loader=tsx --no-warnings' ava --verbose --serial test/*.ava.ts"
},
"author": "",
"license": "Apache-2.0",
Expand All @@ -25,9 +26,17 @@
"@xata.io/client": "workspace:*"
},
"devDependencies": {
"drizzle-orm": "^0.29.0"
"ava": "^5.3.1",
"drizzle-orm": "^0.29.0",
"tsx": "^3.12.7",
"uuid": "^9.0.0"
},
"peerDependencies": {
"drizzle-orm": "^0.28.5"
},
"ava": {
"extensions": {
"ts": "module"
}
}
}
20 changes: 16 additions & 4 deletions packages/plugin-client-drizzle/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { XataClient } from './driver';
import { mapResultRow } from './utils';

type QueryResult<T = Record<string, unknown>> = {
records: T[];
rows: T[];
warning?: string;
};

Expand Down Expand Up @@ -60,10 +60,12 @@ export class XataPreparedQuery<T extends PreparedQueryConfig> extends PreparedQu
params
});

console.debug('execute', { statement: this.query.statement, params, result: records.length, warning });

// FIXME: This is a hack, we should be able to get the fields from the query but SELECT * fails
const fields =
this.fields ??
Object.keys(records[0]!).map(
Object.keys(records[0] ?? {}).map(
(key) =>
({
path: [key],
Expand Down Expand Up @@ -146,11 +148,21 @@ export class XataSession<

async query(query: string, params: unknown[]): Promise<QueryResult> {
this.logger.logQuery(query, params);
return await this.client.sql({ statement: query, params });
const result = await this.client.sql<Record<string, unknown>>({ statement: query, params });

return {
rows: result.records,
warning: result.warning
};
}

async queryObjects<T extends Record<string, unknown>>(query: string, params: unknown[]): Promise<QueryResult<T>> {
return this.client.sql({ statement: query, params });
const result = await this.client.sql<T>({ statement: query, params });

return {
rows: result.records,
warning: result.warning
};
}

override async transaction<T>(
Expand Down
Loading