
Astro DB Has a Free API That Gives You a SQL Database Built Into Your Astro Site
Astro DB is a managed SQL database integrated directly into Astro. Define your schema in TypeScript, query with Drizzle ORM syntax, deploy with your site. Quick Setup npx astro add db Define Schema // db/config.ts import { defineDb , defineTable , column } from ' astro:db ' const Posts = defineTable ({ columns : { id : column . number ({ primaryKey : true }), title : column . text (), content : column . text (), published : column . boolean ({ default : false }), createdAt : column . date ({ default : new Date () }) } }) export default defineDb ({ tables : { Posts } }) Query // In any Astro component or API route import { db , Posts , eq } from ' astro:db ' // Select const allPosts = await db . select (). from ( Posts ) const post = await db . select (). from ( Posts ). where ( eq ( Posts . id , 1 )) // Insert await db . insert ( Posts ). values ({ title : ' Hello ' , content : ' World ' , published : true }) // Update await db . update ( Posts ). set ({ published : true }). where ( eq
Continue reading on Dev.to Webdev
Opens in a new tab


