Skip to content

Commit

Permalink
Fix db.run() type signature in production (#10566)
Browse files Browse the repository at this point in the history
* deps: bump drizzle to latest patch

* chore: changeset

* feat(test): db.run output
  • Loading branch information
bholmesdev authored Mar 26, 2024
1 parent 5f7e9c4 commit b5a8040
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-nails-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Fix `db.run()` type signature in production.
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@libsql/client": "^0.5.5",
"async-listen": "^3.0.1",
"deep-diff": "^1.0.2",
"drizzle-orm": "^0.30.2",
"drizzle-orm": "^0.30.4",
"github-slugger": "^2.0.0",
"kleur": "^4.1.5",
"nanoid": "^5.0.1",
Expand Down
34 changes: 34 additions & 0 deletions packages/db/test/basics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ describe('astro:db', () => {
expect($('.session-id').text()).to.equal('12345');
expect($('.username').text()).to.equal('Mario');
});

it('Prints authors from raw sql call', async () => {
const json = await fixture.fetch('run.json').then((res) => res.json());
expect(json).to.deep.equal({
columns: ['_id', 'name', 'age2'],
columnTypes: ['INTEGER', 'TEXT', 'INTEGER'],
rows: [
[1, 'Ben', null],
[2, 'Nate', null],
[3, 'Erika', null],
[4, 'Bjorn', null],
[5, 'Sarah', null],
],
rowsAffected: 0,
lastInsertRowid: null,
});
});
});

describe('development --remote', () => {
Expand Down Expand Up @@ -137,6 +154,23 @@ describe('astro:db', () => {
expect($('.session-id').text()).to.equal('12345');
expect($('.username').text()).to.equal('Mario');
});

it('Prints authors from raw sql call', async () => {
const json = await fixture.fetch('run.json').then((res) => res.json());
expect(json).to.deep.equal({
columns: ['_id', 'name', 'age2'],
columnTypes: ['INTEGER', 'TEXT', 'INTEGER'],
rows: [
[1, 'Ben', null],
[2, 'Nate', null],
[3, 'Erika', null],
[4, 'Bjorn', null],
[5, 'Sarah', null],
],
rowsAffected: 0,
lastInsertRowid: null,
});
});
});

describe('build --remote', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/db/test/fixtures/basics/src/pages/run.json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="@astrojs/db" />
import type { APIRoute } from 'astro';
import { db, sql } from 'astro:db';

export const GET: APIRoute = async () => {
const authors = await db.run(sql`SELECT * FROM Author`);
return new Response(JSON.stringify(authors), {
headers: {
'content-type': 'application/json',
},
});
};
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5a8040

Please sign in to comment.