An open API service indexing awesome lists of open source software.

https://github.com/tinywasm/postgres

PostgreSQL adapter for tinywasm/orm — pure Go, no CGO, supports WASM-compatible builds
https://github.com/tinywasm/postgres

database golang orm postgres-adapter postgresql tinywasm wasm

Last synced: 2 months ago
JSON representation

PostgreSQL adapter for tinywasm/orm — pure Go, no CGO, supports WASM-compatible builds

Awesome Lists containing this project

README

          

# PostgreSQL Adapter for tinywasm/orm

This repository implements the `orm.Adapter` interface for PostgreSQL, allowing it to be used with the `github.com/tinywasm/orm` library.

## Usage

```go
package main

import (
"log"

"github.com/tinywasm/postgres"
"github.com/tinywasm/orm"
)

func main() {
dsn := "postgres://user:password@localhost:5432/dbname?sslmode=disable"
db, err := postgre.New(dsn)
if err != nil {
log.Fatal(err)
}

// Use db...
}
```

## Features

- Full `orm.Adapter` implementation.
- Transaction support via `BeginTx`.
- Secure SQL generation with parameterized queries using `$1`, `$2`, etc.
- Support for `Create`, `ReadOne`, `ReadAll`, `Update`, `Delete`.
- Efficient row scanning.

## Update

`db.Update` always requires at least one `Condition`. This is enforced at
compile time by `tinywasm/orm`. There is no "update by PK implicitly" magic.

```go
// ✅ Correct
if err := db.Update(&user, orm.Eq(User_.ID, user.ID)); err != nil { ... }

// ❌ Compile error (caught by tinywasm/orm — will not reach the PostgreSQL layer)
db.Update(&user)
```

## Documentation

- [Postgres Setup & Troubleshooting](docs/POSTGRES_SETUP.md)