-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide guidance when --remote is omitted (#10579)
* Provide guidance when --remote is omitted * Only restrict to server mode * Use an AstroError * Update code
- Loading branch information
Showing
11 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@astrojs/db": patch | ||
--- | ||
|
||
Provide guidance when --remote is missing | ||
|
||
When running the build `astro build` without the `--remote`, either require a `DATABASE_FILE` variable be defined, which means you are going expert-mode and having your own database, or error suggesting to use the `--remote` flag. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import db from '@astrojs/db'; | ||
import { defineConfig } from 'astro/config'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [db()], | ||
devToolbar: { | ||
enabled: false, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { column, defineDb, defineTable } from 'astro:db'; | ||
|
||
const User = defineTable({ | ||
columns: { | ||
id: column.text({ primaryKey: true, optional: false }), | ||
username: column.text({ optional: false, unique: true }), | ||
password: column.text({ optional: false }), | ||
}, | ||
}); | ||
|
||
export default defineDb({ | ||
tables: { User }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { asDrizzleTable } from '@astrojs/db/utils'; | ||
import { User, db } from 'astro:db'; | ||
|
||
export default async function () { | ||
await db.batch([ | ||
db.insert(User).values([{ id: 'mario', username: 'Mario', password: 'itsame' }]), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@test/db-local-prod", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview" | ||
}, | ||
"dependencies": { | ||
"@astrojs/db": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/db/test/fixtures/local-prod/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
/// <reference path="../../.astro/db-types.d.ts" /> | ||
import { db, User } from 'astro:db'; | ||
const users = await db.select().from(User); | ||
--- | ||
|
||
<h2>Users</h2> | ||
<ul class="users-list"> | ||
{users.map((user) => <li>{user.name}</li>)} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { expect } from 'chai'; | ||
import testAdapter from '../../astro/test/test-adapter.js'; | ||
import { loadFixture } from '../../astro/test/test-utils.js'; | ||
|
||
describe('astro:db local database', () => { | ||
let fixture; | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: new URL('./fixtures/local-prod/', import.meta.url), | ||
output: 'server', | ||
adapter: testAdapter(), | ||
}); | ||
}); | ||
|
||
describe('build (not remote) with DATABASE_FILE env', () => { | ||
const prodDbPath = new URL('./fixtures/basics/dist/astro.db', import.meta.url).toString(); | ||
before(async () => { | ||
process.env.ASTRO_DATABASE_FILE = prodDbPath; | ||
await fixture.build(); | ||
}); | ||
|
||
after(async () => { | ||
delete process.env.ASTRO_DATABASE_FILE; | ||
}); | ||
|
||
it('Can render page', async () => { | ||
const app = await fixture.loadTestAdapterApp(); | ||
const request = new Request('http://example.com/'); | ||
const response = await app.render(request); | ||
expect(response.status).to.equal(200); | ||
}); | ||
}); | ||
|
||
describe('build (not remote)', () => { | ||
it('should throw during the build for server output', async () => { | ||
delete process.env.ASTRO_DATABASE_FILE; | ||
let buildError = null; | ||
try { | ||
await fixture.build(); | ||
} catch(err) { | ||
buildError = err; | ||
} | ||
|
||
expect(buildError).to.be.an('Error'); | ||
}); | ||
|
||
it('should throw during the build for hybrid output', async () => { | ||
let fixture2 = await loadFixture({ | ||
root: new URL('./fixtures/local-prod/', import.meta.url), | ||
output: 'hybrid', | ||
adapter: testAdapter(), | ||
}); | ||
|
||
delete process.env.ASTRO_DATABASE_FILE; | ||
let buildError = null; | ||
try { | ||
await fixture2.build(); | ||
} catch(err) { | ||
buildError = err; | ||
} | ||
|
||
expect(buildError).to.be.an('Error'); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.