Help us shape the future of Go! Take the 2026 Go Developer Survey

vivom

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2014 License: MIT Imports: 2 Imported by: 0

README

Vivom

dead simple, tiny, but powerful Go ORM library

Usage

Implicitly implement the vivom's interfaces as necessary.

type Subscriber struct {
	ID        int
	Name      string
	Email     string
	DateAdded string
}

func (s *Subscriber) GetID() int {
	return s.ID
}

func (s *Subscriber) SetID(ID int) {
	s.ID = ID
}

func (s *Subscriber) Validate() error {
	if s.Name == "" {
		return errors.New("empty name")
	}

	if s.Email == "" {
		return errors.New("invalid email")
	}

	return nil
}

func (s *Subscriber) Table() string {
	return "subscribers"
}

func (s *Subscriber) Columns() []string {
	return []string{"id", "name", "email", "date_added"}
}

func (s *Subscriber) Values() []interface{} {
	return []interface{}{s.Name, s.Email, time.Now().Unix()}
}

func (s *Subscriber) ScanValues() []interface{} {
	return []interface{}{&s.ID, &s.Name, &s.Email, &t.DateAdded}
}

Import the vivom package

import "github.com/oguzbilgic/vivom"

Now access your records easily using vivom's db functions.

subscriber := &Subscriber{}
err := vivom.Select(subscriber, 23152, db)
if err != nil {
	panic(err)
}

fmt.Println("Subscriber #"+subscriber.ID+" is "+subscriber.Name)

You can also insert new records to the database

subscriber := &Subsriber{Name: "John Doe", Email: "foo@bar.com"}
err := vivom.Insert(subscriber, db)
if err != nil {
	panic(err)
}

fmt.Println("ID of the new subscriber is "+subscriber.ID)

For managing multiple database records, your struct should also implement vivom.TableRows interface.

Documentation

http://godoc.org/github.com/oguzbilgic/vivom

License

The MIT License (MIT)

Documentation

Overview

Package vivom is a dead simple, tiny, but powerful ORM library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InsertableRow

type InsertableRow interface {
	Row

	GetID() int
	SetID(int)
	Validate() error
	Values() []interface{}
}

type Row

type Row interface {
	Table() string

	// Columns returns column names of the table, starting with the primary key.
	Columns() []string
}

type SelectableRow

type SelectableRow interface {
	Row

	ScanValues() []interface{}
}

type SelectableRows

type SelectableRows interface {
	Row

	Next() SelectableRow
}

type Vivom added in v1.0.0

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

func New added in v1.0.0

func New(db *sql.DB) *Vivom

func (*Vivom) Insert added in v1.0.0

func (v *Vivom) Insert(r InsertableRow) error

func (*Vivom) Select added in v1.0.0

func (v *Vivom) Select(r SelectableRow, id string) error

func (*Vivom) SelectAll added in v1.0.0

func (v *Vivom) SelectAll(rs SelectableRows) error

func (*Vivom) SelectAllBy added in v1.0.0

func (v *Vivom) SelectAllBy(rs SelectableRows, column string, value string) error

func (*Vivom) Update added in v1.0.0

func (v *Vivom) Update(r InsertableRow) error

Jump to

Keyboard shortcuts

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