Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/csnewman/cuttle
Opinionated database toolkit for Go
https://github.com/csnewman/cuttle
Last synced: 5 days ago
JSON representation
Opinionated database toolkit for Go
- Host: GitHub
- URL: https://github.com/csnewman/cuttle
- Owner: csnewman
- License: mit
- Created: 2024-04-01T13:57:47.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-05-18T20:50:02.000Z (7 months ago)
- Last Synced: 2024-05-19T18:49:07.264Z (7 months ago)
- Language: Go
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cuttle
Opinionated database toolkit for Go.**Work in progress**: This is incomplete and does not fully function yet!
**Features:**
- TODO
- Transactions
- Batches
- Repository code generator## Codegen
Cuttle optionally includes a repository pattern code generator:
```sql
-- :cuttle version=1
-- :repository name=UsersRepository dialects=sqlite,postgres-- :query name=InsertUser mode=exec
-- :arg name=username type=string
-- :arg name=password type=string
-- :arg name=role type=string
-- :dialect name=sqlite
INSERT INTO users (username, password, role)
VALUES (?1, ?2, ?3);
-- :dialect name=postgres
INSERT INTO users (username, password, role)
VALUES ($1, $2, $3);
```Produces:
```go
package mainimport (
"context"
"github.com/csnewman/cuttle"
)type UsersRepository interface {
InsertUser(
ctx context.Context,
tx cuttle.WTx,
username string,
password string,
role string,
) (int64, error)InsertUserAsync(
tx cuttle.AsyncWTx,
username string,
password string,
role string,
callback cuttle.AsyncHandler[int64],
)
}// [...]
func NewUsersRepository(dialect cuttle.Dialect) (UsersRepository, error) {
// [...]
```## Why not use `database/sql`
TODO
## Drivers
Behind the scenes, cuttle uses the following libraries:
| Database | Library |
|----------|--------------------------------------------------------------------|
| Postgres | [github.com/jackc/pgx](https://github.com/jackc/pgx) |
| SQLite | [github.com/tailscale/sqlite](https://github.com/tailscale/sqlite) |
| Other | TODO (wrapper around `database/sql`) |