orm

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: BSD-3-Clause Imports: 9 Imported by: 1

README

go-orm

Coverage Status Release Go Report Card Build Status

Introduction

The library provides a nice and simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" that is used to interact with this table. Models allow you to query data in tables, as well as insert new records in the table.

DEMO

package main

import (
	"context"
	"database/sql"

	"github.com/deweppro/go-orm"
	"github.com/deweppro/go-orm/plugins"
	"github.com/deweppro/go-orm/schema/mysql"
)

func main() {

	conn, err := mysql.New(&mysql.Config{Pool: []mysql.Item{}})
	if err != nil {
		panic(err.Error())
	}

	db := orm.NewDB(conn, orm.Plugins{Logger: plugins.StdOutLog, Metrics: plugins.StdOutMetric})
	pool := db.Pool("")

	if err = pool.Ping(); err != nil {
		panic(err.Error())
	}

	err = pool.Call("demo_metric", func(conn *sql.Conn, ctx context.Context) error {
		return nil
	})
	if err != nil {
		panic(err.Error())
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB connection storage

func NewDB

func NewDB(c schema.Connector, plug Plugins) *DB

NewDB init database connections

func (*DB) Pool

func (d *DB) Pool(name string) StmtInterface

Pool getting pool connections by name

type Plugins

type Plugins struct {
	Logger  logger.Logger
	Metrics plugins.MetricGetter
}

Plugins storage

type Result

type Result struct {
	Err  error
	Rows int64
}

Result model

func (*Result) Error

func (r *Result) Error() error

Err ...

func (*Result) RowsAffected

func (r *Result) RowsAffected() int64

RowsAffected ...

type Resulter added in v1.0.1

type Resulter interface {
	Error() error
	RowsAffected() int64
}

Resulter interface

type Stmt

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

Stmt statement model

func (*Stmt) Call

func (s *Stmt) Call(name string, fn func(*sql.Conn, context.Context) error) error

Call basic query execution

func (*Stmt) Ping

func (s *Stmt) Ping() error

Ping database ping

func (*Stmt) Tx

func (s *Stmt) Tx(name string, fn func(*sql.Tx, context.Context) error) error

Tx the basic execution of a query in a transaction

type StmtInterface

type StmtInterface interface {
	Call(string, func(*sql.Conn, context.Context) error) error
	Tx(string, func(*sql.Tx, context.Context) error) error
	Ping() error
}

StmtInterface statement interface

type TableName

type TableName string

TableName field of table name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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