Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.17 KB

File metadata and controls

52 lines (37 loc) · 1.17 KB

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

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.

// ✅ 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