feat: switch to Astro DB for guestbook
- Add @astrojs/db integration - Define Guestbook schema in db/config.ts - Add seed data for development - Update db.ts to use astro:db - Add guestbook section to homepage with form - Update env vars to use ASTRO_DB_REMOTE_URL
This commit is contained in:
parent
4e2c09b770
commit
79c7aff48b
9 changed files with 365 additions and 37 deletions
16
apps/blog/db/config.ts
Normal file
16
apps/blog/db/config.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { defineDb, defineTable, column } from 'astro:db';
|
||||
|
||||
const Guestbook = defineTable({
|
||||
columns: {
|
||||
id: column.number({ primaryKey: true }),
|
||||
name: column.text(),
|
||||
message: column.text(),
|
||||
url: column.text({ optional: true }),
|
||||
createdAt: column.date({ default: new Date() }),
|
||||
approved: column.boolean({ default: false }),
|
||||
},
|
||||
});
|
||||
|
||||
export default defineDb({
|
||||
tables: { Guestbook },
|
||||
});
|
||||
22
apps/blog/db/seed.ts
Normal file
22
apps/blog/db/seed.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { db, Guestbook } from 'astro:db';
|
||||
|
||||
export default async function seed() {
|
||||
await db.insert(Guestbook).values([
|
||||
{
|
||||
id: 1,
|
||||
name: 'alice',
|
||||
message: 'love the site!',
|
||||
url: 'https://example.com',
|
||||
createdAt: new Date('2026-01-20'),
|
||||
approved: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'bob',
|
||||
message: 'great blog posts',
|
||||
url: null,
|
||||
createdAt: new Date('2026-01-18'),
|
||||
approved: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue