Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlrows

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package sqlrows reads a database/sql result into a batch: Polars' read_database (step 353). A column's type is its values', their kinds met as Polars meets the values of a column it builds from rows, and then the type its driver names it, where every value fits that type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(rows *sql.Rows, o Options) (*data.Batch, error)

Read reads every row of rows and closes it.

Types

type Dialect added in v0.6.8

type Dialect int

Dialect is how a SQL database spells what a write says to it (step 366): its placeholders, its quoting, its columns' types and its limits. database/sql cannot name it, so a caller names it, or the driver's package does.

const (
	DialectUnknown Dialect = iota
	SQLite
	Postgres
	MySQL
	SQLServer
)

func DialectOf added in v0.6.8

func DialectOf(driver any) Dialect

DialectOf names the dialect of a database/sql driver, or of a driver connection, by its package: modernc's and mattn's SQLite, pgx's and lib/pq's PostgreSQL, the MySQL driver, and Microsoft's and denisenkom's SQL Server.

func (Dialect) ColumnType added in v0.6.8

func (d Dialect) ColumnType(t dtype.DataType) (string, error)

ColumnType is the type a column of t is created as, the one ReadDatabase reads back as t where the database keeps it. A List, an Array, a Struct and a Duration have none, and are refused by name.

func (Dialect) CreateTable added in v0.6.8

func (d Dialect) CreateTable(table string, s *dtype.Schema) (string, error)

CreateTable is the statement that creates table with the columns of s.

func (Dialect) DropTable added in v0.6.8

func (d Dialect) DropTable(table string) string

DropTable drops table, if it is there.

func (Dialect) Exists added in v0.6.8

func (d Dialect) Exists(table string) (string, []any)

Exists is a query of one row and one value, nonzero or true when table exists, and its arguments: SQLite's catalogue, PostgreSQL's to_regclass, MySQL's information_schema, SQL Server's OBJECT_ID. Each finds the table as a statement naming it would, in the schema the name gives or the connection's own.

func (Dialect) Insert added in v0.6.8

func (d Dialect) Insert(table string, cols []string, rows int) string

Insert is an INSERT of rows rows into table's columns cols.

func (Dialect) Placeholder added in v0.6.8

func (d Dialect) Placeholder(n int) string

Placeholder is the nth parameter's marker, from 1.

func (Dialect) Quote added in v0.6.8

func (d Dialect) Quote(name string) string

Quote is name as one identifier: in double quotes, as the standard and SQLite and PostgreSQL quote it, in backquotes for MySQL, in brackets for SQL Server, each doubling its closing quote within.

func (Dialect) RowsPerInsert added in v0.6.8

func (d Dialect) RowsPerInsert(width int) int

RowsPerInsert is how many rows of width columns one INSERT takes: as many as its parameters allow, at most a thousand, the most SQL Server takes in one VALUES. SQLite's are 999, the least any of its builds allows; SQL Server's 2,100 a statement.

func (Dialect) String added in v0.6.8

func (d Dialect) String() string

func (Dialect) Table added in v0.6.8

func (d Dialect) Table(name string) string

Table is a table's name, its parts split at each dot, as Polars splits "schema.table", each part quoted.

type Options

type Options struct {
	// Overrides types columns by name, as Polars' schema_overrides does: each value
	// is cast to its column's type, and one that does not fit it is an error.
	Overrides map[string]dtype.DataType
}

Options are what a read is told.

Jump to

Keyboard shortcuts

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