sql

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sql provides a database client implementation that uses SQL.

Index

Constants

View Source
const (
	DriverAmazonDynamoDB     = Driver("godynamo")
	DriverMicrosoftSQLServer = Driver("sqlserver")
	DriverMySQL              = Driver("mysql")
	DriverOracle             = Driver("oracle")
	DriverPostgres           = Driver("postgres")
	DriverSQLite             = Driver("sqlite3")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a struct that provides client related methods.

func (*Client) BeginTransaction

func (this *Client) BeginTransaction() error

BeginTransaction begins a transaction.

finally, you must call EndTransaction.

ex)

err := client.BeginTransaction()

err = client.ExecuteTransaction(`...`)

err = client.EndTransaction(err)

func (*Client) Close

func (this *Client) Close() error

Close closes the database.

ex) err := client.Close()

func (*Client) EndTransaction

func (this *Client) EndTransaction(err error) error

EndTransaction ends a transaction.

if the argument is nil, commit is performed; otherwise, rollback is performed.

ex)

err := client.BeginTransaction()

err = client.ExecuteTransaction(`...`)

err = client.EndTransaction(err)

func (*Client) Execute

func (this *Client) Execute(query string, args ...any) error

Execute executes the query.

ex 1) err := client.Execute(`INSERT INTO ... VALUES(value);`) ex 2) err := client.Execute(`INSERT INTO ... VALUES(?);`, value)

func (*Client) ExecutePrepare

func (this *Client) ExecutePrepare(args ...any) error

ExecutePrepare executes a prepared statement.

ex)

err := client.SetPrepare(`INSERT INTO ` + table + `(field) VALUE(?);`)

err = client.ExecutePrepare(value)

func (*Client) ExecutePrepareTransaction

func (this *Client) ExecutePrepareTransaction(args ...any) error

ExecutePrepareTransaction executes a prepared statement.

ex)

err := client.SetPrepareTransaction(`INSERT INTO ` + table + ` VALUE(field=?);`)

err = client.ExecutePrepareTransaction(value)

func (*Client) ExecuteTransaction

func (this *Client) ExecuteTransaction(query string, args ...any) error

ExecuteTransaction executes a query.

ex 1) err := client.ExecuteTransaction(`...`)

ex 2) err := client.ExecuteTransaction(`... WHERE field=?;`, value)

func (*Client) Open

func (this *Client) Open(driver Driver, dsn string, maxOpenConnection int) error

Open opens the database.

ex) err := client.Open(sql.DriverMySQL, `id:password@tcp(address)/table`, 1)

func (*Client) Query

func (this *Client) Query(query string, args ...any) (*sql.Rows, error)

Query executes a query and returns the result rows.

ex)

rows, err := client.Query(`SELECT field ...;`)

defer rows.Close()

for rows.Next() {
    field := 0
    err := rows.Scan(&field)
}

func (*Client) QueryPrepare

func (this *Client) QueryPrepare(args ...any) (*sql.Rows, error)

QueryPrepare query a prepared statement.

ex)

err := client.SetPrepare(`SELECT field ... WHERE field=?;`)

rows, err := client.QueryPrepare(value)

defer rows.Close()

for rows.Next() {
    field := 0
    err := rows.Scan(&field)
}

func (*Client) QueryPrepareTransaction

func (this *Client) QueryPrepareTransaction(args ...any) (*sql.Rows, error)

QueryPrepareTransaction is query a prepared statement.

ex)

err := client.SetPrepareTransaction(`SELECT field ... WHERE field=?;`)

rows, err := client.QueryPrepareTransaction(value)

defer rows.Close()

for rows.Next() {
    field := 0
    err := rows.Scan(&field)
}

func (*Client) QueryRow

func (this *Client) QueryRow(query string, result ...any) error

QueryRow executes a query and copies the values of matched rows.

ex) err := client.QueryRow(`SELECT field FROM ...;`, &field)

func (*Client) QueryRowPrepare

func (this *Client) QueryRowPrepare(args ...any) (*sql.Row, error)

QueryRowPrepare query a prepared statement about row.

ex)

err := client.SetPrepare(`SELECT field ... WHERE field=?;`)

row, err := client.QueryRowPrepare(value)

field := 0
err := row.Scan(&field)

func (*Client) QueryRowPrepareTransaction

func (this *Client) QueryRowPrepareTransaction(args ...any) (*sql.Row, error)

QueryPrepareTransaction query a prepared statement about row.

ex)

err := client.SetPrepareTransaction(`SELECT field ... WHERE field=?;`)

row, err := client.QueryRowPrepareTransaction(value)

field := 0
err := row.Scan(&field)

func (*Client) QueryRowTransaction

func (this *Client) QueryRowTransaction(query string, result ...any) error

QueryRowTransaction executes a query and copies the values of matched rows.

ex) err := client.QueryRowTransaction(`SELECT field ...;`, &field)

func (*Client) QueryTransaction

func (this *Client) QueryTransaction(query string, args ...any) (*sql.Rows, error)

QueryTransaction executes a query and returns the result rows.

ex 1) rows, err := client.QueryTransaction(`SELECT field ... WHERE field=value;`) ex 2) rows, err := client.QueryTransaction(`SELECT field ... WHERE field=?;`, "value")

defer rows.Close()

for rows.Next() {
    field := 0
    err := rows.Scan(&field)
}

func (*Client) SetPrepare

func (this *Client) SetPrepare(query string) error

SetPrepare is set prepared statement.

ex)

err := client.SetPrepare(`SELECT field ... WHERE field=?;`)
err := client.ExecutePrepare(value)

func (*Client) SetPrepareTransaction

func (this *Client) SetPrepareTransaction(query string) error

SetPrepareTransaction is set prepared statement.

ex) err := client.SetPrepareTransaction(`SELECT field ... WHERE field=?;`)

type Driver

type Driver string

Jump to

Keyboard shortcuts

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