diff --git a/packages/db/test/fixtures/glob/astro.config.ts b/packages/db/test/fixtures/glob/astro.config.ts new file mode 100644 index 0000000000..af9545d625 --- /dev/null +++ b/packages/db/test/fixtures/glob/astro.config.ts @@ -0,0 +1,30 @@ +import { defineConfig } from 'astro/config'; +import db, { defineCollection, field } from '@astrojs/db'; +import glob from 'fast-glob'; +import { readFile } from 'fs/promises'; + +const Quote = defineCollection({ + fields: { + author: field.text(), + body: field.text(), + }, + async data() { + const quotes = await glob('quotes/*.json'); + return Promise.all( + quotes.map(async (quote) => { + const data = JSON.parse(await readFile(quote, 'utf-8')); + return { + author: data.author, + body: data.body, + }; + }) + ); + }, +}); + +export default defineConfig({ + db: { + collections: { Quote }, + }, + integrations: [db()], +}); diff --git a/packages/db/test/fixtures/glob/package.json b/packages/db/test/fixtures/glob/package.json new file mode 100644 index 0000000000..5866b4cf42 --- /dev/null +++ b/packages/db/test/fixtures/glob/package.json @@ -0,0 +1,19 @@ +{ + "name": "glob", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "astro dev", + "build": "astro build", + "preview": "astro preview" + }, + "dependencies": { + "@astrojs/db": "workspace:*", + "astro": "workspace:*", + "fast-glob": "^3.3.2" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/packages/db/test/fixtures/glob/quotes/erika.json b/packages/db/test/fixtures/glob/quotes/erika.json new file mode 100644 index 0000000000..c7ece9ca6e --- /dev/null +++ b/packages/db/test/fixtures/glob/quotes/erika.json @@ -0,0 +1,4 @@ +{ + "author": "Erika", + "body": "Put the quote in the database." +} diff --git a/packages/db/test/fixtures/glob/quotes/tony.json b/packages/db/test/fixtures/glob/quotes/tony.json new file mode 100644 index 0000000000..3aaed7746b --- /dev/null +++ b/packages/db/test/fixtures/glob/quotes/tony.json @@ -0,0 +1,4 @@ +{ + "author": "Tony Sull", + "body": "All content is data, but not all data is content." +} diff --git a/packages/db/test/fixtures/glob/src/pages/index.astro b/packages/db/test/fixtures/glob/src/pages/index.astro new file mode 100644 index 0000000000..6d2fdf22c0 --- /dev/null +++ b/packages/db/test/fixtures/glob/src/pages/index.astro @@ -0,0 +1,25 @@ +--- +/// +import { Quote, db } from 'astro:db'; + +const quotes = await db.select().from(Quote); +--- + + + + + + + Document + + + { + quotes.map((q) => ( +
+
{q.body}
+
{q.author}
+
+ )) + } + +