Skip to content

michael/svelte-postgres-demo

Repository files navigation

svelte-postgres-demo

A starting point for connecting SvelteKit with Postgres. Write pure SQL and save yourself the headaches with object relational mappers.

In api.js you can access the database like this:

export async function createTodo (userId, { text, done }) {
  return db.one('INSERT INTO todos(user_id, text, done) VALUES($1, $2, $3) RETURNING *', [userId, text, done]);
}

Development

Make sure you have a Postgres DB instance running and provide your connection string as an environment variable.

VITE_DB_URL=postgresql://postgres@localhost:5432/svelte-postgres-demo
psql -Atx $VITE_DB_URL -f schema.sql

Now run the development server:

npm run dev

Questions?

Ping @_mql on Twitter.

About

Sveltekit and Postgres

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published