Categorygithub.com/elsagg/schemaless-data-go
modulepackage
1.0.1
Repository: https://github.com/elsagg/schemaless-data-go.git
Documentation: pkg.go.dev

# README

go-schemaless

Build Status

A basic implementation of schemaless data on mysql inspired by Uber

Installing

go get github.com/elsagg/schemaless-data-go

Usage

package main

import (
	"log"

	"github.com/elsagg/schemaless-data-go"
)

// you can define your own data models
type Person struct {
	FirstName string `msgpack:"first_name"` // changing the field name stored in database by msgpack
	LastName  string
}

func main() {

	// Define a connection object
	conn := schemaless.NewConnection(&schemaless.ConnectionOptions{
		Host:       "localhost",
		Port:       "3306",
		Username:   "root",
		Password:   "mysecretpass",
		Parameters: map[string]string{"parseTime": "true"}, // Custom database parameters
	})

	// Define a DataSource, aka: shard
	// the package will take care of creating the database and the table
	ds := schemaless.NewDataSource("people", conn)

	p := Person{
		FirstName: "John",
		LastName:  "Doe",
	}

	// Creating a new data cell
	cell, err := ds.PutCell(
        "3c4eecc2-84df-466b-a023-9c044c289934",
        "PERSONAL_INFO",
        &p,
	)

	if err != nil {
		log.Fatal(err)
	}

	log.Println(cell.AddedID)
}

API's

DataSource

PutCell will create and return a new cell

PutCell(RowKey string, ColumnKey string, Body interface{}) (*DataCell, error)

GetCell will return a cell by given arguments

GetCell(RowKey string, ColumnKey string, RefKey int) (*DataCell, error)

GetCellLatest will search for the latest RefKey of a cell an return it

GetCellLatest(RowKey string, ColumnKey string) (*DataCell, error)

GetAllLatest will search for the latest RefKey of all cells by a given ColumnKey

GetAllLatest(ColumnKey string) (*[]DataCell, error)

DataCell

MarshalBody will receive any data type and convert to a msgpack binary, then save it to DataCell.Body

MarshalBody(v interface{}) (err error)

UnmarshalBody will convert the msgpack binary in DataCell.Body back to a data type

UnmarshalBody(v interface{}) (err error)

# Functions

NewConnection creates a Connection.
NewDataSource returns a new DataSource instance.

# Constants

Query constants.
Query constants.
Query constants.
Query constants.
Query constants.

# Structs

Connection connects to a database.
ConnectionOptions sets the options for Connection.
DataCell represents a data cell in the database.
DataSource is a data source.