orm

package module
v0.0.0-...-2bcc06d Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

Build Status

orm

Simple wrapper for Hyperledger Fabric 0.6 tables.

Use at your own risk, it's an early version and the interface may change.

Usage

    type User struct {
        FirstName string
        orm.Saveable // This adds an Id field and makes sure we can save.
    }
    
    // Create table
    user := new(User)  
 	if err := orm.CreateTable(stub, user); err != nil {  
 		return nil, errors.Wrap(err, "Failed creating table.")  
 	}  
  
    // Create User
 	arne := User{FirstName: "Arne"}  
 	if err := orm.Create(stub, &arne); err != nil {  
 		return nil, errors.Wrap(err, "Failed creating user.")  
 	}  
 	
 	// Get User with Id 1
    var user User  
    if err := orm.Get(stub, &user, 1); err != nil {  
        return nil, err  
    }  
    
    // Update User
    user.FirstName = "Dave"  
    if err := orm.Update(stub, &user); err != nil {  
        return nil, err  
    }  
    
    // Delete User
    if err := orm.Delete(stub, &user); err != nil {    
        return nil, err  
    }  

Documentation

Overview

Package orm provides a simple wrapper for Hyperledger Fabric tables.

Add an anonymous field orm.Saveable to your entities. At initialization, create a table as follows:

user := new(User)

if err := orm.CreateTable(stub, user); err != nil {
  return nil, errors.Wrap(err, "Failed creating table.")
}

For more info, see the README.md on github

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

Insert a row for the item in the database

func CreateTable

func CreateTable(stub shim.ChaincodeStubInterface, item BlockchainItemizer) error

Create a table of the passed item. Types are automatically inferred.

func Delete

Delete an item

func Get

Get an item by Id

func GetAll

func GetAll(stub shim.ChaincodeStubInterface, items interface{}) error

Get all items by passing a slice of the correct type

func Update

Update an item

Types

type BlockchainItemizer

type BlockchainItemizer interface {
	GetId() int64
	SetId(int64)
}

Items need to implement this interface to use ORM. You can use an anonymous Saveable in your struct.

type Saveable

type Saveable struct {
	Id int64 `json:"id" key:"true"`
}

Place an anonymous Saveable in your struct to use ORM.

func (*Saveable) GetId

func (s *Saveable) GetId() int64

func (*Saveable) SetId

func (s *Saveable) SetId(id int64)

Jump to

Keyboard shortcuts

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