sqliter

package module
v0.0.0-...-c4e6139 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: MIT Imports: 7 Imported by: 0

README

Summary

SQLiter provides a simplified interface for storing flat structs to disk. It is meant to be easy to use and quick to get started but not to be particularly powerful.

The utility is in adding structored data persistence to a golang project in just a few lines of code.

Usage

Init

type MyStruct struct {
    ID    int64  `db:"id" attr:"PRIMARY KEY"`
    Value string `db:"value"`
}

db, _ := sqliter.Open(dbName)
db.CreateTable(MyStruct{})

Insert

db.Insert(MyStruct{Value:"foo"})

Read

myStruct := &MyStruct{}
db.ReadOne(myStruct, "id = ?", 1)

Update

myStruct.Value = "bar"
db.Update(myStruct, "id = ?", 1)

Delete

db.Delete(MyStruct{}, "id = ?", 1)

Documentation

Index

Constants

View Source
const InMemory = ":memory:"

Variables

This section is empty.

Functions

This section is empty.

Types

type Sqliter

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

func Open

func Open(filename string) (*Sqliter, error)

func (*Sqliter) Close

func (s *Sqliter) Close()

func (*Sqliter) CreateTable

func (s *Sqliter) CreateTable(sample interface{}) error

func (*Sqliter) Delete

func (s *Sqliter) Delete(sample interface{}, where string, args ...interface{}) error

func (*Sqliter) DeleteFrom

func (s *Sqliter) DeleteFrom(table, where string, args ...interface{}) error

func (*Sqliter) Exec

func (s *Sqliter) Exec(q string, args ...interface{}) (sql.Result, error)

func (*Sqliter) Insert

func (s *Sqliter) Insert(obj interface{}) (int64, error)

func (*Sqliter) ReadMany

func (s *Sqliter) ReadMany(outPtr interface{}, where string, args ...interface{}) error

func (*Sqliter) ReadOne

func (s *Sqliter) ReadOne(outPtr interface{}, where string, args ...interface{}) error

func (*Sqliter) Update

func (s *Sqliter) Update(obj interface{}, where string, args ...interface{}) error

func (*Sqliter) Upsert

func (s *Sqliter) Upsert(obj interface{}, where string, args ...interface{}) (int64, error)

type StructField

type StructField struct {
	Key   string
	Value interface{}
	Type  reflect.Type
	Attr  string
}

Jump to

Keyboard shortcuts

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