pachsql

package
v2.9.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ProtocolPostgres = "postgres"
	ProtocolMySQL    = "mysql"
)

Variables

This section is empty.

Functions

func CreateTestTable

func CreateTestTable(db *DB, name string, schema interface{}) error

CreateTestTable creates a test table at name in the database

func Placeholder

func Placeholder(driverName string, i int) string

Placeholder returns a placeholder for the given driver assuming i placeholders have been provided before it. It is 0 indexed in this way.

This means that the first Postgres placeholder is `$1` when i = 0. This is more ergonimic for contructing a list of arguments since i = len(args) but is perhaps unintuitive for those familiar with Postgres.

func SplitTableSchema

func SplitTableSchema(driver string, tablePath string) (schemaName string, tableName string)

SplitTableSchema splits the tablePath on the first . and interprets the first part as the schema, if the driver supports schemas.

Types

type ColumnInfo

type ColumnInfo struct {
	Name       string
	DataType   string
	IsNullable bool
}

ColumnInfo is information about a single column in a SQL table

type DB

type DB = sqlx.DB

DB is an alias for sqlx.DB which is the standard database type used throughout the project

func OpenURL

func OpenURL(u URL, password string) (*DB, error)

OpenURL returns a database connection pool to the database specified by u If password != "" then it will be used for authentication. This function does not confirm that the database is reachable; callers may be interested in pachsql.DB.Ping()

type PGDumpReader

type PGDumpReader struct {
	Header []byte
	Footer []byte
	// contains filtered or unexported fields
}

PGDumpReader parses a pgdump file into a header, rows, and a footer

func NewPGDumpReader

func NewPGDumpReader(r *bufio.Reader) *PGDumpReader

NewPGDumpReader creates a new PGDumpReader

func (*PGDumpReader) ReadRow

func (r *PGDumpReader) ReadRow() ([]byte, error)

ReadRow parses the pgdump file and populates the header and the footer It returns EOF when done, and at that time both the Header and Footer will be populated. Both header and footer are required. If either are missing, an error is returned

type RowMap

type RowMap = map[string]interface{}

RowMap is an alias for map[string]interface{} which is the type used by sqlx.MapScan()

type SchemaTable

type SchemaTable struct {
	SchemaName string `json:"schemaname"`
	TableName  string `json:"tablename"`
}

SchemaTable stores a given table's name and schema.

func ListTables

func ListTables(ctx context.Context, db *DB) ([]SchemaTable, error)

ListTables returns an array of SchemaTable structs that represent the tables.

type Stmt

type Stmt = sqlx.Stmt

Stmt is an alias for sqlx.Stmt which is the standard prepared statement type used throught the project

type TableInfo

type TableInfo struct {
	Driver  string
	Name    string
	Schema  string
	Columns []ColumnInfo
}

TableInfo contains information about a SQL table

func GetTableInfo

func GetTableInfo(ctx context.Context, db *DB, tableName string) (*TableInfo, error)

GetTableInfo looks up information about the table using INFORMATION_SCHEMA

func GetTableInfoTx

func GetTableInfoTx(tx *Tx, tablePath string) (*TableInfo, error)

GetTableInfoTx looks up information about the table using INFORMATION_SCHEMA

func (*TableInfo) ColumnNames

func (t *TableInfo) ColumnNames() []string

type TestRow

type TestRow struct {
	Id int16 `column:"c_id" dtype:"SMALLINT" constraint:"PRIMARY KEY NOT NULL"`

	Smallint     int16     `column:"c_smallint" dtype:"SMALLINT" constraint:"NOT NULL"`
	Int          int32     `column:"c_int" dtype:"INT" constraint:"NOT NULL"`
	Bigint       int64     `column:"c_bigint" dtype:"BIGINT" constraint:"NOT NULL"`
	Float        float32   `column:"c_float" dtype:"FLOAT" constraint:"NOT NULL"`
	NumericInt   int64     `column:"c_numeric_int" dtype:"NUMERIC(20,0)" constraint:"NOT NULL"`
	NumericFloat float64   `column:"c_numeric_float" dtype:"NUMERIC(20,19)" constraint:"NOT NULL"`
	Varchar      string    `column:"c_varchar" dtype:"VARCHAR(100)" constraint:"NOT NULL"`
	Time         time.Time `column:"c_time" dtype:"TIMESTAMP" constraint:"NOT NULL"`

	SmallintNull     sql.NullInt16   `column:"c_smallint_null" dtype:"SMALLINT" constraint:"NULL"`
	IntNull          sql.NullInt32   `column:"c_int_null" dtype:"INT" constraint:"NULL"`
	BigintNull       sql.NullInt64   `column:"c_bigint_null" dtype:"BIGINT" constraint:"NULL"`
	FloatNull        sql.NullFloat64 `column:"c_float_null" dtype:"FLOAT" constraint:"NULL"`
	NumericIntNull   sql.NullInt64   `column:"c_numeric_int_null" dtype:"NUMERIC(20,0)" constraint:"NULL"`
	NumericFloatNull sql.NullFloat64 `column:"c_numeric_float_null" dtype:"NUMERIC(20,19)" constraint:"NULL"`
	VarcharNull      sql.NullString  `column:"c_varchar_null" dtype:"VARCHAR(100)" constraint:"NULL"`
	TimeNull         sql.NullTime    `column:"c_time_null" dtype:"TIMESTAMP" constraint:"NULL"`
}

TestRow is the type of a row in the test table struct tag: sql:"<column_name>,<data_type>,<table_constraint>"

func (*TestRow) SetID

func (row *TestRow) SetID(id int16)

type Tx

type Tx = sqlx.Tx

Tx is an alias for sqlx.Tx which is the standard transaction type used throughout the project

type URL

type URL struct {
	Protocol string
	User     string
	Host     string
	Port     uint16
	Database string
	Schema   string
	Params   map[string]string
}

URL contains the information needed to connect to a SQL database, except for the password.

func ParseURL

func ParseURL(x string) (*URL, error)

ParseURL attempts to parse x into a URL

func (*URL) String

func (u *URL) String() string

Jump to

Keyboard shortcuts

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