0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -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.

82 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-01-25 11:49:44 -05:00
import { defineConfig } from 'astro/config';
2024-01-26 15:42:31 -05:00
import astroDb, { defineCollection, field } from '@astrojs/db';
2024-01-25 11:49:44 -05:00
const Recipe = defineCollection({
fields: {
2024-01-25 13:40:38 -05:00
id: field.number({ primaryKey: true, optional: true }),
2024-01-25 11:49:44 -05:00
title: field.text(),
description: field.text(),
},
});
const Ingredient = defineCollection({
fields: {
2024-01-25 13:40:38 -05:00
id: field.number({ primaryKey: true, optional: true }),
2024-01-25 11:49:44 -05:00
name: field.text(),
quantity: field.number(),
recipeId: field.text(),
},
2024-01-29 17:50:15 -05:00
indexes: {
recipeIdx: { on: 'recipeId', unique: true },
},
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-01-26 15:42:31 -05:00
async data({ seed }) {
const pancakes = await seed(Recipe, {
2024-01-25 13:40:38 -05:00
title: 'Pancakes',
description: 'A delicious breakfast',
});
2024-01-25 11:49:44 -05:00
2024-01-26 15:42:31 -05:00
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-01-26 15:42:31 -05:00
const pizza = await seed(Recipe, {
2024-01-25 13:40:38 -05:00
title: 'Pizza',
description: 'A delicious dinner',
});
2024-01-26 15:42:31 -05:00
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
},
},
});