si

package module
v2.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 2 Imported by: 0

README

si(storage interface)

Go Reference codecov Go Report Card

si is a package designed to help developers (mostly myself) read and write data to various destinations by wrapping standard and non-standard packages. Its main function is to convert between structs and primary types (bytes, strings, etc.), allowing you to skip the encoding and decoding routines.

Installation

go get -u github.com/wonksing/si/v2

Quick Start

  1. sql
connStr := "host=testpghost port=5432 user=test password=test123 dbname=testdb sslmode=disable connect_timeout=60"
driver := "postgres"
db, _ := sql.Open(driver, connStr)
sqldb := sisql.NewSqlDB(db).WithTagKey("si")

type BoolTest struct {
    Nil      string `json:"nil" si:"nil"`
    True_1   bool   `json:"true_1" si:"true_1"`
    True_2   bool   `json:"true_2" si:"true_2"`
    False_1  bool   `json:"false_1" si:"false_1"`
    False_2  bool   `json:"false_2" si:"false_2"`
    Ignore_3 string `si:"-"`
}
query := `
    select null as nil,
        null as true_1, '1' as true_2, 
        0 as false_1, '0' as false_2
    union all
    select null as nil,
        1 as true_1, '1' as true_2,
        0 as false_1, '0' as false_2
`

m := []BoolTest{}
_, err := sqldb.QueryStructs(query, &m)

Test

Test flags include the following.

  • ONLINE_TEST
    • Runs tests that actually connect to the storages such as PostgreSQL database.
  • LONG_TEST
    • Runs tests that takes long time to complete.

Examples of running the tests.

ONLINE_TEST=1 LONG_TEST=1 go test ./...
ONLINE_TEST=1 go test -run SKIP -bench . -benchtime 100x -benchmem

Versions

v2.2.1

Documentation

Overview

Package si implements wrappers around standard and non-standard packages to read and write data to storages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenSqlDB

func OpenSqlDB(driver, dsn string, maxIdleConns, maxOpenConns int, connMaxLifetime time.Duration) (*sql.DB, error)

Types

This section is empty.

Directories

Path Synopsis
example
sql
experimental
Package internal is the internal package.
Package internal is the internal package.
tests

Jump to

Keyboard shortcuts

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