ark

package module
v0.1.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

README

go-ark

Go data mapper providing a familiar API for internally supported database providers.

Installation

go-ark may be installed using the go get command:

go get github.com/pghq/go-ark

Usage

A typical usage scenario:

import (
    "context"
    
    "github.com/pghq/go-ark/database"
    "github.com/pghq/go-ark"
)

//go:embed schema
var schema embed.FS

// Open a postgres connection
db, err := ark.New("postgres://user:pass@postgres/db", database.Migrate(schema))
if err != nil{
    panic(err)
}

// Create a transaction
tx := db.Txn(context.Background())
defer tx.Rollback()

// Commit some data
if err := tx.Insert("foos", map[string]interface{}{"id": "foo"}); err != nil{
    panic(err)
}

if err := tx.Commit(); err != nil{
    panic(err)
}

Supported Providers

  • Postgres
  • Redshift

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocumentDecoder added in v0.1.2

type DocumentDecoder interface {
	Decode(fn func(v interface{}) error) error
}

DocumentDecoder decodes a database document.

type DocumentEncoder added in v0.1.5

type DocumentEncoder interface {
	Encode() interface{}
}

DocumentEncoder encodes a database document

type Mapper added in v0.0.31

type Mapper struct {
	// contains filtered or unexported fields
}

Mapper Data mapper for various backends

func New added in v0.0.35

func New(dsn string, opts ...database.Option) (*Mapper, error)

New Create a new mapper

func (*Mapper) Do added in v0.0.35

func (m *Mapper) Do(ctx context.Context, fn func(tx Txn) error, opts ...database.TxnOption) error

Do Write and or read using a callback

func (*Mapper) Txn added in v0.0.35

func (m *Mapper) Txn(ctx context.Context, opts ...database.TxnOption) Txn

Txn Begin or fork a transaction

func (*Mapper) View added in v0.0.35

func (m *Mapper) View(ctx context.Context, fn func(tx Txn) error, opts ...database.TxnOption) error

View Read using a callback

type Txn added in v0.0.35

type Txn struct {
	// contains filtered or unexported fields
}

Txn A unit of work

func (Txn) Commit added in v0.0.35

func (tx Txn) Commit() error

Commit Submit a unit of work

func (Txn) Context added in v0.1.23

func (tx Txn) Context() context.Context

Context gets the context of the transaction

func (Txn) Get added in v0.0.35

func (tx Txn) Get(table string, query database.Query, v interface{}) error

Get Retrieve a value

func (Txn) Insert added in v0.0.35

func (tx Txn) Insert(table string, v interface{}) error

Insert insert a value

func (Txn) List added in v0.0.35

func (tx Txn) List(table string, query database.Query, v interface{}) error

List Retrieve a listing of values

func (Txn) Remove added in v0.0.35

func (tx Txn) Remove(table string, query database.Query) error

Remove Delete a value by key

func (Txn) Rollback added in v0.0.35

func (tx Txn) Rollback() error

Rollback Cancel a unit of work

func (Txn) Update added in v0.0.35

func (tx Txn) Update(table string, query database.Query, v interface{}) error

Update Replace an existing value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL