0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-10 22:38:53 -05:00
astro/packages/db/test/fixtures/recipes/astro.config.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-01-25 11:49:44 -05:00
import { defineConfig } from 'astro/config';
2024-02-20 15:29:17 -05:00
import astroDb, { defineCollection, column } from '@astrojs/db';
2024-01-25 11:49:44 -05:00
const Recipe = defineCollection({
2024-02-20 15:29:17 -05:00
columns: {
id: column.number({ primaryKey: true }),
title: column.text(),
description: column.text(),
2024-01-25 11:49:44 -05:00
},
});
const Ingredient = defineCollection({
2024-02-20 15:29:17 -05:00
columns: {
id: column.number({ primaryKey: true }),
name: column.text(),
quantity: column.number(),
recipeId: column.number(),
2024-01-25 11:49:44 -05:00
},
2024-01-29 17:50:15 -05:00
indexes: {
recipeIdx: { on: 'recipeId' },
2024-01-29 17:50:15 -05:00
},
2024-02-20 15:29:17 -05:00
foreignKeys: [{ columns: 'recipeId', references: () => [Recipe.columns.id] }],
2024-01-25 11:49:44 -05:00
});
export default defineConfig({
2024-01-26 15:42:31 -05:00
integrations: [astroDb()],
2024-01-25 11:49:44 -05:00
db: {
collections: { Recipe, Ingredient },
2024-02-13 11:37:29 -05:00
async data({ seed, seedReturning }) {
const pancakes = await seedReturning(Recipe, {
2024-01-25 13:40:38 -05:00
title: 'Pancakes',
description: 'A delicious breakfast',
});
2024-01-25 11:49:44 -05:00
2024-02-13 11:37:29 -05:00
await seed(Ingredient, [
2024-01-25 13:40:38 -05:00
{
name: 'Flour',
quantity: 1,
recipeId: pancakes.id,
},
{
name: 'Eggs',
quantity: 2,
recipeId: pancakes.id,
},
{
name: 'Milk',
quantity: 1,
recipeId: pancakes.id,
},
]);
2024-02-13 11:37:29 -05:00
const pizza = await seedReturning(Recipe, {
2024-01-25 13:40:38 -05:00
title: 'Pizza',
description: 'A delicious dinner',
});
2024-02-13 11:37:29 -05:00
await seed(Ingredient, [
2024-01-25 13:40:38 -05:00
{
name: 'Flour',
quantity: 1,
recipeId: pizza.id,
},
{
name: 'Eggs',
quantity: 2,
recipeId: pizza.id,
},
{
name: 'Milk',
quantity: 1,
recipeId: pizza.id,
},
{
name: 'Tomato Sauce',
quantity: 1,
recipeId: pizza.id,
},
]);
2024-01-25 11:49:44 -05:00
},
},
});