horm

package module
v0.1.4-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

README

Introdution

horm is an ORM-like lib to map go struct to HBase columns,
It provides CURD interface for HBase.

Quick Start

package main

import (
	"context"
	"fmt"

	"github.com/challenai/horm"
	"github.com/challenai/horm/client"
)

type User struct {
	*horm.Model
	Name string `hbase:"family,name"` // column family = family, column name = name
	Age  int    `hbase:"family,age"`  // column family = family, column name = age
}

func (*User) Namespace() string {
	return "namespace"
}

func (*User) TableName() string {
	return "user"
}

func main() {
	const (
		addr   = ""
		rowkey = "id0001"
	)

	ctx := context.Background()
	headers := []client.Header{
		{Key: "header1", Value: ""},
	}
	hb, err := horm.NewHBase(addr, headers)
	if err != nil {
		panic(err)
	}

	user := &User{}
	err = hb.Get(ctx, user, rowkey).Error
	if err != nil {
		println(err)
		return
	}
	fmt.Println(user.Name, user.Age)
}

Documentation

Index

Constants

View Source
const (
	HBaseTagHint    string = "horm"
	ModelName       string = "Model"
	RowName         string = "Rowkey"
	BatchResultSize int32  = 1 << 6 // todo: selft-customized batchResultSize, default set to be 64KB (assume 1KB bytes per row)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Family    string
	Name      string
	Timestamp int64
}

column is a column in HBase column family, used to pick columns to query

type Conf

type Conf struct {
	Cdc codec.Codec
	Log logger.Logger
}

type DB

type DB struct {
	Error        error
	RowsAffected int64
	// contains filtered or unexported fields
}

DB represent a HBase database

func NewDB

func NewDB(client *hbase.THBaseServiceClient, conf *Conf) *DB

create a new hbase database from thrift client

func NewHBase

func NewHBase(addr string, headers []client.Header) (*DB, error)

NewHBase create a new HBase DB

func NewHBaseWithCodec

func NewHBaseWithCodec(addr string, headers []client.Header, codec c.Codec) (*DB, error)

NewHBase create a new HBase DB

func NewHBaseWithLog

func NewHBaseWithLog(addr string, headers []client.Header, log logger.Logger) (*DB, error)

NewHBaseWithLog create a new HBase DB

func (*DB) BatchDelete

func (h *DB) BatchDelete(ctx context.Context, model interface{}, rows []Row) *DB

func (*DB) BatchSet

func (h *DB) BatchSet(ctx context.Context, rows interface{}, selects []Column) *DB

func (*DB) CreateModel

func (h *DB) CreateModel(ctx context.Context, model interface{}) *DB

func (*DB) CreateNamespace

func (h *DB) CreateNamespace(ctx context.Context, namespace string) *DB

func (*DB) Delete

func (h *DB) Delete(ctx context.Context, model interface{}, rowkey string, columns []Column) *DB

func (*DB) Find

func (h *DB) Find(ctx context.Context, list interface{}, startRow, stopRow string, selects []Column, filter *Filter) *DB

HBase rows range query

func (*DB) Get

func (h *DB) Get(ctx context.Context, model interface{}, rowkey string) *DB

get a single row.

func (*DB) Set

func (h *DB) Set(ctx context.Context, model interface{}, selects []Column) *DB

insert or update model to HBase

type Filter

type Filter struct {
	FilterString string
	Limit        int32
}

filter input raw filter string and rows limit to thrift server

type Model

type Model struct {
	Rowkey string
}

base model for every hbase model

type Row

type Row struct {
	Rowkey  string
	Columns []Column
}

type Table

type Table interface {
	Namespace() string
	TableName() string
}

Model should implement Table interface to specify the namespace and table name.

Directories

Path Synopsis
thrift

Jump to

Keyboard shortcuts

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