sqlite3

package module
v0.0.0-...-ee3efe4 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: 0BSD Imports: 14 Imported by: 0

README

go-driver for sqlite3, using the pre-compiled sqlite3 CLI

I was getting pretty tired of the cgo compile times for other sqlite drivers.

Current implementation writes the sql command to sqlite3's stdin, followed by .print ''', which tells us when the output ends.

sqlite's stdout & stderr are set to be the same, so any errors are printed before "'''".

A better way may involve named pipes & .output. Running the following:

mkfifo commands data
printf '%s\n' '.output data' 'SELECT * FROM table;' > commands &
echo .read commands | strace sqlite3

Gives the following (abridged) strace output:

read(0, ".read commands\n")
open("commands") = 4
read(4, ".output data\nSELECT * FROM table;\n")
open( "data") = 5
write(2, "Parse error near line 2: near \"t"...)
read(4, "")
close(4)
close(5)

sqlite3 provieds no way to configure the error output, however, it writes the error message before it closes the data FD.

In C, with select, we'd be able to select over sqlite's stderr & the data pipe, and if either:

  • stderr is ready to read
  • stderr is ready to read & data pipe is ready to read & returns EOF

Under those conditions, we know there's an error & the error is only for us.

This repo proves that if data is written to 1 pipe & another is closed, select will always report it in the correct order: https://github.com/jeremybobbin/select-test

This is not possible in idiomatic go because go is for kids.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	context.Context
	// contains filtered or unexported fields
}

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

func (*Conn) Close

func (c *Conn) Close() (err error)

func (*Conn) IsValid

func (c *Conn) IsValid(dial context.Context) bool

func (*Conn) Ping

func (c *Conn) Ping(ctx context.Context) (err error)

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(_ context.Context, query string) (driver.Stmt, error)

func (*Conn) ResetSession

func (c *Conn) ResetSession(dial context.Context) error

type Connector

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

func (*Connector) Connect

func (c *Connector) Connect(dial context.Context) (driver.Conn, error)

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

type Driver

type Driver struct {
}

func (*Driver) Open

func (d *Driver) Open(name string) (driver.Conn, error)

func (*Driver) OpenConnector

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

type ParseError

type ParseError struct {
	Parser
	// contains filtered or unexported fields
}

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

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

type ReadCloser

type ReadCloser struct {
	bufio.Reader
	// contains filtered or unexported fields
}

func (*ReadCloser) Close

func (r *ReadCloser) Close() error

type Result

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

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

type Rows

type Rows struct {
	Result
	Parser
	// contains filtered or unexported fields
}

func (*Rows) Close

func (r *Rows) Close() error

func (*Rows) Columns

func (r *Rows) Columns() []string

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) (err error)

type Stmt

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

func (*Stmt) Close

func (s *Stmt) Close() error

func (*Stmt) Exec

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

func (*Stmt) Query

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

type Tx

type Tx struct {
	*Conn
}

func (*Tx) Commit

func (c *Tx) Commit() error

func (*Tx) Rollback

func (c *Tx) Rollback() error

Jump to

Keyboard shortcuts

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