norm

package module
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 7 Imported by: 0

README

norm

An ORM library support nGQL for Golang.

go report card Go MIT license Go.Dev reference

Overview

  • Build insert nGQL by struct / map (Support vertex, edge).
  • Parse Nebula execute result to struct / map.
  • Easy to use.
  • Easy mock for Unit Testing.

Roadmap

  1. Session pool. For details, please see dialector
  2. Support more types in insert/execute function.
    • Types: time.Time
  3. Support batch insert, query list.
  4. Chainable api. For detail please see chainable api

Maybe Support

  • Statistic Hooks. Insert/Query count and latency.
  • Fix fields Order when build insert nGQL. (now norm use map store keys, and in go range map is out-of-order.)

Need improve

  • Benchmark.
  • Unit Testing.
  • Documents.

Getting Started

Install:

go get github.com/zhihu/norm

use example: please go use example

Contributing guidelines

License

© Zhihu, 2021~time.Now

Released under the MIT License

copy and paste from gorm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVidWithPolicy

func GetVidWithPolicy(vid interface{}, policy constants.Policy) string

Types

type Config

type Config struct {
	DebugMode bool
	// contains filtered or unexported fields
}

func (*Config) LoadDefault

func (config *Config) LoadDefault()

type DB

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

func MustOpen

func MustOpen(dialector dialectors.IDialector, cfg Config, opts ...Option) *DB

MustOpen 语法糖. 如果 error 则 panic, 适用于强依赖 db 的场景

func Open

func Open(dialector dialectors.IDialector, cfg Config, opts ...Option) (*DB, error)

Open initialize nebula connect pool

func (*DB) Bidirect

func (db *DB) Bidirect() (tx *DB)

Bidirect over egde bidirect

func (*DB) Close

func (db *DB) Close()

Close

func (*DB) Count

func (db *DB) Count(out interface{}) error

Count 计算符合条件的数据数量

func (*DB) Debug

func (db *DB) Debug() (tx *DB)

Debug will print the nGql when it exec

func (*DB) DebugMode

func (db *DB) DebugMode()

DebugMode 调试模式, 会输出任意语句的sql

func (*DB) Execute

func (db *DB) Execute(sql string) (*dialectors.ResultSet, error)

Execute 执行某条sql

func (*DB) ExecuteAndParse

func (db *DB) ExecuteAndParse(sql string, in interface{}) error

ExecuteAndParse 执行某条sql, 然后解析为传入的结构. in 可以是 map[string]interface{}, *Strcut, *[]map, *[]struct

func (*DB) From

func (db *DB) From(vs ...IVertex) (tx *DB)

func (*DB) Go

func (db *DB) Go(step int) (tx *DB)

func (*DB) Group

func (db *DB) Group(fields ...string) (tx *DB)

func (*DB) InsertEdge

func (db *DB) InsertEdge(in IEdge) error

InsertEdge 解析结构体, 然后插入一条边.

func (*DB) InsertVertex

func (db *DB) InsertVertex(in IVertex) error

InsertVertex 解析结构体, 然后插入一个点.

func (*DB) Limit

func (db *DB) Limit(limit int) (tx *DB)

func (*DB) Over

func (db *DB) Over(edges ...IEdge) (tx *DB)

func (*DB) Return

func (db *DB) Return(out interface{}) error

Return 返回数据并将结果反序列化到 out 结构体中

func (*DB) ReturnRow

func (db *DB) ReturnRow() (*dialectors.ResultSet, error)

ReturnRow 返回 nsql 执行的原始结果, 不进行任何加工

func (*DB) Reversely

func (db *DB) Reversely() (tx *DB)

Reversely over egde reversely

func (*DB) UpsertEdge

func (db *DB) UpsertEdge(in IEdge) error

UpsertEdge 解析结构体, 然后插入 Upsert 一条边.

func (*DB) UpsertVertex

func (db *DB) UpsertVertex(in IVertex) error

UpsertVertex 解析结构体, 然后 Upsert 一个点.

func (*DB) Where

func (db *DB) Where(sql string) (tx *DB)

func (*DB) Yield

func (db *DB) Yield(sql string) (tx *DB)

type DefaultLogger

type DefaultLogger = nebula.DefaultLogger

type EModel

type EModel struct {
	Src       interface{}      `norm:"-"`
	SrcPolicy constants.Policy `norm:"-"`
	Dst       interface{}      `norm:"-"`
	DstPolicy constants.Policy `norm:"-"`
}

func (EModel) EdgeName

func (v EModel) EdgeName() string

func (EModel) GetVidDst

func (v EModel) GetVidDst() interface{}

func (EModel) GetVidDstPolicy

func (v EModel) GetVidDstPolicy() constants.Policy

func (EModel) GetVidSrc

func (v EModel) GetVidSrc() interface{}

func (EModel) GetVidSrcPolicy

func (v EModel) GetVidSrcPolicy() constants.Policy

type IEdge

type IEdge interface {
	// 返回边的名称
	EdgeName() string
	GetVidSrc() interface{}
	GetVidSrcPolicy() constants.Policy
	GetVidDst() interface{}
	GetVidDstPolicy() constants.Policy
}

type ITag

type ITag interface {
	TagName() string
}

type IVertex

type IVertex interface {
	ITag
	GetVid() interface{}
	GetPolicy() constants.Policy
}

type Logger

type Logger = nebula.Logger

type Option

type Option func(c *Config)

func WithLogger

func WithLogger(logger Logger) Option

type VModel

type VModel struct {
	Vid    interface{}      `norm:"-"`
	Policy constants.Policy `norm:"-"`
}

vid is int or string

func (VModel) GetPolicy

func (v VModel) GetPolicy() constants.Policy

func (VModel) GetVid

func (v VModel) GetVid() interface{}

func (VModel) TagName

func (v VModel) TagName() string

Directories

Path Synopsis
* * package: dialectors * file: dirlector.go * author: wuzhensheng * create: 2021-06-23 11:52:00 * description: *
* * package: dialectors * file: dirlector.go * author: wuzhensheng * create: 2021-06-23 11:52:00 * description: *
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
internal

Jump to

Keyboard shortcuts

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