https://github.com/michael/svelte-postgres-demo
Sveltekit and Postgres
https://github.com/michael/svelte-postgres-demo
Last synced: 8 months ago
JSON representation
Sveltekit and Postgres
- Host: GitHub
- URL: https://github.com/michael/svelte-postgres-demo
- Owner: michael
- Created: 2022-05-10T13:52:22.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-10T17:21:54.000Z (about 4 years ago)
- Last Synced: 2025-02-28T18:34:24.835Z (over 1 year ago)
- Language: Svelte
- Size: 498 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 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](./src/lib/api.js) you can access the database like this:
```js
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.
```zsh
VITE_DB_URL=postgresql://postgres@localhost:5432/svelte-postgres-demo
psql -Atx $VITE_DB_URL -f schema.sql
```
Now run the development server:
```zsh
npm run dev
```
## Questions?
Ping @_mql on Twitter.