ssorm

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 14 Imported by: 0

README

SSORM

SSORM is a simple spanner orm for Golang

Overview

  • Feature

    • Insert (Model)
    • Update (Model and Columns and Params)
    • Find (Model)
    • First (Model)
    • Count (Model)
    • Delete (Model and Where)
    • SubQuery (Model)
    • SoftDelete (Insert Update Find First Count Delete SubQuery)
    • SimpleQueryRead
    • SimpleQueryWrite
  • Supported data type

    • STRING
    • INT64
    • FLOAT64
    • ARRAY
    • BOOL
    • DATE
    • TIMESTAMP
  • SSORM Tag

    • primary
    • create_time
    • update_time
    • delete_time
    • ignore_write
    • nullable_write

Test

  • Configure spanner-emulator && create instance && create database && insert record

    . ./tests/ddl/create_datbase.sh
    
  • Run test

    go test -v ./tests/...
    

Custom Logger

ssorm.Logger({custom logger})

Logger Interface

type ILogger interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})
WithContext(ctx context.Context) *logrus.Entry
}

Tracing

ssorm.UseTracing()

Additional Tracing Option

import (
  "go.opentelemetry.io/otel/trace"

  "github.com/10antz-inc/ssorm"
  "github.com/10antz-inc/ssorm/ssormotel"
)

func main() {
  ssorm.UseTrace(
    // add attribute 'db.statement'
    ssormotel.WithQueryStatement(),
    // set the created TraceProvider.
    ssormotel.WithTraceProvider(provider trace.TraceProvider),
    // add any attribute
    ssormotel.WithAttributes(
      semconv.DBConnectionStringKey.String("projects/.../instances/.../databases/..."),
      semconv.DBSystemKey.String("Google Cloud Spanner"),
    )
  )
}

License

Copyright (c) 2021 10ANTZ, Inc.

SSORM is released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(l ILogger)

func SimpleQueryRead added in v0.0.8

func SimpleQueryRead(ctx context.Context, spannerTransaction interface{}, query string, params map[string]interface{}, result interface{}) error

func SimpleQueryWrite added in v0.0.8

func SimpleQueryWrite(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction, query string, params map[string]interface{}) (int64, error)

func UseTrace added in v0.4.0

func UseTrace(opts ...ssormotel.Option)

Types

type Builder

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

type DB

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

func Model

func Model(model interface{}, opts ...Option) *DB

func SoftDeleteModel

func SoftDeleteModel(model interface{}, opts ...Option) *DB

func (*DB) AddSub

func (db *DB) AddSub(model interface{}, query interface{}, values ...interface{}) *DB

func (*DB) Count

func (db *DB) Count(ctx context.Context, spannerTransaction interface{}, cnt interface{}) error

func (*DB) DeleteModel

func (db *DB) DeleteModel(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction) (int64, error)

func (*DB) DeleteWhere

func (db *DB) DeleteWhere(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction) (int64, error)

func (*DB) Find

func (db *DB) Find(ctx context.Context, spannerTransaction interface{}) error

func (*DB) First

func (db *DB) First(ctx context.Context, spannerTransaction interface{}) error

func (*DB) Insert

func (db *DB) Insert(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction) (int64, error)

func (*DB) Limit

func (db *DB) Limit(limit int64) *DB

func (*DB) Offset

func (db *DB) Offset(offset int64) *DB

func (*DB) Order

func (db *DB) Order(order string) *DB

func (*DB) Select

func (db *DB) Select(query []string) *DB

func (*DB) TableName

func (db *DB) TableName(tableName string) *DB

func (*DB) Update

func (db *DB) Update(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction) (int64, error)

func (*DB) UpdateColumns

func (db *DB) UpdateColumns(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction, in []string) (int64, error)

func (*DB) UpdateOmit added in v0.2.1

func (db *DB) UpdateOmit(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction, in []string) (int64, error)

func (*DB) UpdateParams

func (db *DB) UpdateParams(ctx context.Context, spannerTransaction *spanner.ReadWriteTransaction, in map[string]interface{}) (int64, error)

func (*DB) Where

func (db *DB) Where(query interface{}, values ...interface{}) *DB

type ILogger

type ILogger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})
	WithContext(ctx context.Context) *logrus.Entry
}

func NewLogger

func NewLogger(out io.Writer) ILogger

type Option

type Option func(*DB)

type SubBuilder

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

Directories

Path Synopsis
instrumentation

Jump to

Keyboard shortcuts

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