Documentation
¶
Overview ¶
Package gopglite provides a database/sql driver for PGlite, an embedded PostgreSQL database compiled to WebAssembly.
This package uses wazero (a pure Go WebAssembly runtime) to run PGlite directly without requiring Node.js or any external processes.
Usage ¶
To use gopglite with database/sql:
import (
"database/sql"
_ "github.com/bradfitz/gopglite"
)
func main() {
db, err := sql.Open("pglite", ":memory:")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Use db as a standard *sql.DB
}
Data Directory Options ¶
The data source name (DSN) specifies where to store the database:
- ":memory:" - In-memory database (data lost when closed)
- "/path/to/dir" - Persistent storage in the specified directory
Package gopglite implements the PostgreSQL wire protocol for PGlite.
Index ¶
- type Conn
- func (c *Conn) Begin() (driver.Tx, error)
- func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *Conn) Close() error
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(query string) (driver.Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- type Connector
- type DB
- type Driver
- type Result
- type Rows
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn implements driver.Conn for PGlite.
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext implements driver.ExecerContext.
func (*Conn) PrepareContext ¶
PrepareContext implements driver.ConnPrepareContext.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector manages a PGlite instance and provides connections to it.
func NewConnector ¶
NewConnector creates a new Connector for the given data directory.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a PGlite database instance.
func Open ¶
Open opens a PGlite database. The dataDir parameter is currently ignored - an in-memory temporary directory is used.
type Driver ¶
type Driver struct{}
Driver implements database/sql/driver.Driver for PGlite.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result implements driver.Result.
func (*Result) LastInsertId ¶
func (*Result) RowsAffected ¶
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows implements driver.Rows.
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt implements driver.Stmt.