Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshnuss/requel
Import SQL files with Vite
https://github.com/joshnuss/requel
postgres sql typescript vite
Last synced: 3 months ago
JSON representation
Import SQL files with Vite
- Host: GitHub
- URL: https://github.com/joshnuss/requel
- Owner: joshnuss
- Created: 2024-07-16T20:48:41.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-20T04:23:56.000Z (6 months ago)
- Last Synced: 2024-07-21T04:38:04.796Z (6 months ago)
- Topics: postgres, sql, typescript, vite
- Language: TypeScript
- Homepage:
- Size: 263 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Requel
Type-safe `.sql` files with Vite.
## Usage
Add the plugin in `vite.config.ts`
```ts
import { defineConfig } from 'vite'
import { requel } from 'vite-plugin-requel'export default defineConfig({
plugins: [ requel() ]
})
```Add `DATABASE_URL` to the `.env` file.
Then, initialize the repo:
```bash
pnpx requel init
```Pull the database schema:
```bash
pnpx requel db pull
```Create a `.sql` file, for example `db/products.sql`.
**Note**: input params can be typed via front matter
```sql
---
minPrice: integer
---select *
from products
where price > :minPrice
```Import the `.sql` file:
```ts
import { query } from '$db/products.sql'// input params and output rows are full typed
const rows = await query({ minPrice: 100 })
```## Related projects
- [Drizzle](https://orm.drizzle.team)
- [Prisma](https://www.prisma.io)
- [Kysely](https://kysely.dev)
- [TypeSQL](https://github.com/wsporto/typesql)## License
MIT