Neon Postgres & Astro
هذا المحتوى غير متوفر بلغتك بعد.
Neon is a fully managed serverless Postgres database. It separates storage and compute to offer autoscaling, branching, and bottomless storage.
Adding Neon to your Astro project
Section titled Adding Neon to your Astro projectPrerequisites
Section titled Prerequisites- A Neon account with a created project
- Neon database connection string
- An Astro project with on-demand rendering (SSR) enabled
Environment configuration
Section titled Environment configurationTo use Neon with Astro, you will need to set a Neon environment variable. Create or edit the .env
file in your project root, and add the following code, replacing your own project details:
For better TypeScript support, define environment variables in a src/env.d.ts
file:
.env
files in Astro.
Installing dependencies
Section titled Installing dependenciesInstall the @neondatabase/serverless
package to connect to Neon:
Creating a Neon client
Section titled Creating a Neon clientCreate a new file src/lib/neon.ts
with the following code to initialize your Neon client:
Querying your Neon database
Section titled Querying your Neon databaseYou can now use the Neon client to query your database from any .astro
component. The following example fetches the current time from the Postgres database:
Database branching with Neon
Section titled Database branching with NeonNeon’s branching feature lets you create copies of your database for development or testing. Use this in your Astro project by creating different environment variables for each branch:
Resources
Section titled Resources- Neon documentation
- Neon serverless driver GitHub
- Connect an Astro site or application to Neon Postgres