#How to add astro db to vercel

4 messages · Page 1 of 1 (latest)

deft prawn
#

How to add astro db to vercel

silk pikeBOT
#

Hi @deft prawn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To add Astro DB to your Astro project and deploy it on Vercel, you need to follow these steps:

  1. Add Astro DB to your project:
    You can use the astro add command to automate the setup of official integrations like Astro DB. Run one of the following commands in a new terminal window:

    npx astro add db
    

    or

    pnpm astro add db
    

    or

    yarn astro add db
    

    If you prefer to set things up manually, you can install Astro DB yourself. First, install the integration from npm via a package manager:

    npm install @astrojs/db
    

    or

    pnpm add @astrojs/db
    

    or

    yarn add @astrojs/db
    

    Then, add the integration to astro.config.mjs:

    import { defineConfig } from 'astro/config';
    import db from '@astrojs/db';
    export default defineConfig({ integrations: [ db() ]});
    

    Finally, configure your database by creating a db/config.ts file at the root of your project. This is a special file that Astro will automatically load and use to configure your database tables:

    import { defineDb } from 'astro:db';
    export default defineDb({ tables: {},})
    

    Source (https://docs.astro.build/en/guides/integrations-guide/db#installation)

  2. Deploy your project to Vercel:
    You can deploy your project to Vercel either by CLI (vercel deploy) or by connecting your new repo in the Vercel Dashboard (https://vercel.com/). Alternatively, you can create a production build locally:

    astro build
    vercel deploy --prebuilt
    

    Source (https://docs.astro.build/en/guides/integrations-guide/vercel#usage)

#

Please note that you need to have the Vercel CLI installed to deploy your project using the CLI. You can install it using npm install -g vercel.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: