sqlite3_js

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

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

Go to latest
Published: Feb 28, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

go-sqlite3-js

Experimental SQL driver for sql.js (in-browser sqlite) from Go WASM.

Only implements the subset of the SQL API required by Dendrite.

To run tests in Docker and Node:

$ docker build -t gsj .
$ docker run gsj

To run tests locally:

$ yarn install
$ GOOS=js GOARCH=wasm go test -exec="./go_sqlite_js_wasm_exec" .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SqliteJsConn

type SqliteJsConn struct {
	JsDb js.Value // sql.js SQL.Database : https://sql-js.github.io/sql.js/documentation/class/Database.html
	// contains filtered or unexported fields
}

SqliteJsConn implements driver.Conn.

func (*SqliteJsConn) Begin

func (conn *SqliteJsConn) Begin() (driver.Tx, error)

Begin starts a transaction. The default isolation level is dependent on the driver.

func (*SqliteJsConn) BeginTx

func (conn *SqliteJsConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx starts and returns a new transaction. If the context is canceled by the user the sql package will call Tx.Rollback before discarding and closing the connection.

This must check opts.Isolation to determine if there is a set isolation level. If the driver does not support a non-default level and one is set or if there is a non-default isolation level that is not supported, an error must be returned.

This must also check opts.ReadOnly to determine if the read-only value is true to either set the read-only transaction property if supported or return an error if it is not supported.

func (SqliteJsConn) Close

func (conn SqliteJsConn) Close() error

Close returns the connection to the connection pool. All operations after a Close will return with ErrConnDone. Close is safe to call concurrently with other operations and will block until all other operations finish. It may be useful to first cancel any used context and then call close directly after.

func (*SqliteJsConn) Exec

func (conn *SqliteJsConn) Exec(query string, args []driver.Value) (result driver.Result, err error)

func (*SqliteJsConn) Prepare

func (conn *SqliteJsConn) Prepare(query string) (stmt driver.Stmt, err error)

Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.

type SqliteJsDriver

type SqliteJsDriver struct {
	ConnectHook func(*SqliteJsConn) error
}

SqliteJsDriver implements driver.Driver.

func (*SqliteJsDriver) Open

func (d *SqliteJsDriver) Open(dsn string) (conn driver.Conn, err error)

Open a database "connection" to a SQLite database.

type SqliteJsResult

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

SqliteJsResult implements sql.Result.

func (*SqliteJsResult) LastInsertId

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

LastInsertId return last inserted ID.

func (*SqliteJsResult) RowsAffected

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

RowsAffected return how many rows affected.

type SqliteJsRows

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

SqliteJsRows implements driver.Rows.

func (*SqliteJsRows) Close

func (r *SqliteJsRows) Close() error

Close closes the rows iterator.

func (*SqliteJsRows) Columns

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

Columns returns the names of the columns. The number of columns of the result is inferred from the length of the slice. If a particular column name isn't known, an empty string should be returned for that entry.

func (*SqliteJsRows) Next

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

Next is called to populate the next row of data into the provided slice. The provided slice will be the same size as the Columns() are wide.

Next should return io.EOF when there are no more rows.

The dest should not be written to outside of Next. Care should be taken when closing Rows not to modify a buffer held in dest.

type SqliteJsStmt

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

SqliteJsStmt implements driver.Stmt.

func (*SqliteJsStmt) Close

func (s *SqliteJsStmt) Close() error

Close closes the statement.

func (*SqliteJsStmt) Exec

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

Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.

func (*SqliteJsStmt) ExecContext

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

ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.

ExecContext must honor the context timeout and return when it is canceled.

func (*SqliteJsStmt) Next

func (s *SqliteJsStmt) Next() *js.Value

func (*SqliteJsStmt) NumInput

func (s *SqliteJsStmt) NumInput() int

NumInput returns the number of placeholder parameters.

If NumInput returns >= 0, the sql package will sanity check argument counts from callers and return errors to the caller before the statement's Exec or Query methods are called.

NumInput may also return -1, if the driver doesn't know its number of placeholders. In that case, the sql package will not sanity check Exec or Query argument counts.

func (*SqliteJsStmt) Query deprecated

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

Query executes a query that may return rows, such as a SELECT.

Deprecated: Drivers should implement StmtQueryContext instead (or additionally).

func (*SqliteJsStmt) QueryContext

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

QueryContext executes a query that may return rows, such as a SELECT.

QueryContext must honor the context timeout and return when it is canceled.

type SqliteJsTx

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

SqliteJsTx implements driver.Tx.

func (*SqliteJsTx) Commit

func (tx *SqliteJsTx) Commit() error

Commit commits the transaction.

func (*SqliteJsTx) Rollback

func (tx *SqliteJsTx) Rollback() error

Rollback aborts the transaction.

Jump to

Keyboard shortcuts

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