Skip to content

Commit

Permalink
feat(test): db.run output
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Mar 26, 2024
1 parent ce6a48d commit 5d6d788
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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',
},
});
};

0 comments on commit 5d6d788

Please sign in to comment.