Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Drizzle] Add integration tests #1151

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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.28.5"
"ava": "^5.3.1",
"drizzle-orm": "^0.28.5",
"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