sqlds

package module
v0.0.0-...-239b36c Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: MIT Imports: 7 Imported by: 1

README

SQL Datastore

An implementation of the datastore interface that can be backed by any sql database.

Usage

import (
	"database/sql"
	"github.com/whyrusleeping/sql-datastore"
)

mydb, _ := sql.Open("yourdb", "yourdbparameters")

ds := sqlds.NewSqlDatastore(mydb)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType = errors.New("invalid value type")
)

Functions

func NewQueriesForTable

func NewQueriesForTable(tableName string) *queries

func QueryWithParams

func QueryWithParams(d *Datastore, q dsq.Query) (*sql.Rows, error)

QueryWithParams applies prefix, limit, and offset params in pg query

Types

type Datastore

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

func NewDatastore

func NewDatastore(db *sql.DB, queries Queries) *Datastore

NewDatastore returns a new datastore

func (*Datastore) Batch

func (d *Datastore) Batch() (ds.Batch, error)

func (*Datastore) Close

func (d *Datastore) Close() error

func (*Datastore) Delete

func (d *Datastore) Delete(key ds.Key) error

func (*Datastore) Get

func (d *Datastore) Get(key ds.Key) (value []byte, err error)

func (*Datastore) GetSize

func (d *Datastore) GetSize(key ds.Key) (int, error)

func (*Datastore) Has

func (d *Datastore) Has(key ds.Key) (exists bool, err error)

func (*Datastore) Put

func (d *Datastore) Put(key ds.Key, value []byte) error

func (*Datastore) Query

func (d *Datastore) Query(q dsq.Query) (dsq.Results, error)

func (*Datastore) RawQuery

func (d *Datastore) RawQuery(q dsq.Query) (dsq.Results, error)

func (*Datastore) Sync

func (*Datastore) Sync(prefix ds.Key) error

Sync guarantees that any Put or Delete calls under prefix that returned before Sync(prefix) was called will be observed after Sync(prefix) returns, even if the program crashes. If Put/Delete operations already satisfy these requirements then Sync may be a no-op.

If the prefix fails to Sync this method returns an error.

type Options

type Options struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
	Table    string
}

Options are the postgres datastore options, reexported here for convenience.

func (*Options) CreatePostgres

func (opts *Options) CreatePostgres() (*Datastore, error)

Create returns a datastore connected to postgres initialized with a table

type Queries

type Queries interface {
	Delete() string
	Exists() string
	Get() string
	Put() string
	Query() string
	Prefix() string
	Limit() string
	Offset() string
	GetSize() string
}

Jump to

Keyboard shortcuts

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