sqljs

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

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

Go to latest
Published: Apr 13, 2017 License: MIT Imports: 6 Imported by: 0

README

Build Status GoDoc

This package provides GopherJS bindings around SQL.js, and a database/sql/driver implementation, for use with the standard Go Database driver infrastructure.

SQL.js is SQLite compiled to JavaScript through Emscripten, which can run in the browser. If your goal is to use SQLite from Go, you should use mattn/go-sqlite3 or go-sqlite instead. If your intention is to use SQLite within GopherJS running on node.js, you should probably use the sqlite3 package instead (which as far as I know, has no GopherJS bindings at the moment).

To be clear: You should only use this package if you are writing code for GopherJS which must run in the browser.

This does not support storing databases on the filesystem--it only supports in-memory databases (which may be imported from binary blobs). The database/sql driver also does not support transactions (what value would they be in an in-memory, in-browser database, anyway?)

Build instructions

As this package provides bindings for a JavaScript package, naturally the JavaScript must be installed to successfully use these bindings. In your GopherJS package, which depends on this one, you can add a package.json which includes sql.js as a dependency, then run npm install prior to building the GopherJS package.

Documentation

Rendered for js/wasm

Overview

Package sqljs provides a database/sql-compatible interface to SQL.js (https://github.com/lovasoa/sql.js) for GopherJS.

SQL.js does not provide anything like a complete SQLite3 API, and this module even less so. This module exists for one primary purpose: To be able to read SQLite3 databases from within a browser. For such purposes, only a small subset of features is considered useful. To this end, this module is tested only for reading databases. Although writes are supported, there is currently no way to export the database using this package. Also, transactions are not supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReader

func AddReader(name string, reader io.Reader) error

Types

type SQLJSConn

type SQLJSConn struct {
	*bindings.Database
}

Connection struct

func (*SQLJSConn) Begin

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

Begin a transaction -- not supported (will always return an error)

func (*SQLJSConn) Close

func (c *SQLJSConn) Close() error

Close the database and free memory.

func (*SQLJSConn) Prepare

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

Prepare the query string. Return a new statement handle.

type SQLJSDriver

type SQLJSDriver struct{}

Driver struct. To load an existing database, you must register a new instance of this driver, with an io.Reader pointing to the SQLite3 database file. See Open() for an example.

func (*SQLJSDriver) Open

func (d *SQLJSDriver) Open(dsn string) (driver.Conn, error)

Open will a new database instance. By default, it will create a new database in memory. To open an existing database, you must first register a new instance as the driver. The DSN string is always ignored.

Example:

driver := &sqljs.SQLJSDriver{}
sql.Register("sqljs-reader", driver)
file, _ := os.Open("/path/to/database.db")
driver.Reader, _ = file
db := sql.Open("sqljs-reader","")

type SQLJSResult

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

Result struct.

func (SQLJSResult) LastInsertId

func (SQLJSResult) LastInsertId() (int64, error)

LastInsertId is not supported. It will always return an error.

func (*SQLJSResult) RowsAffected

func (s *SQLJSResult) RowsAffected() (int64, error)

RowsAffected is not supported. It will always return an error.

type SQLJSRows

type SQLJSRows struct {
	*bindings.Statement
	// contains filtered or unexported fields
}

Rows struct.

func (*SQLJSRows) Close

func (r *SQLJSRows) Close() error

Close closes the Rows iterator.

func (*SQLJSRows) Columns

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

Columns returns the names of the columns.

func (*SQLJSRows) Next

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

Next is called to populate the next row of data into the provided slice.

type SQLJSStmt

type SQLJSStmt struct {
	*bindings.Statement
	// contains filtered or unexported fields
}

Statement struct.

func (*SQLJSStmt) Close

func (s *SQLJSStmt) Close() error

Close the statement handler.

func (*SQLJSStmt) Exec

func (s *SQLJSStmt) Exec(args []driver.Value) (r driver.Result, e error)

Exec executes a query that does not return any rows.

func (*SQLJSStmt) NumInput

func (s *SQLJSStmt) NumInput() int

NumInput is unsupported. It will always return -1.

func (*SQLJSStmt) Query

func (s *SQLJSStmt) Query(args []driver.Value) (r driver.Rows, e error)

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

Directories

Path Synopsis
Package bindings provides minimal GopherJS bindings around the SQL.js (https://github.com/lovasoa/sql.js)
Package bindings provides minimal GopherJS bindings around the SQL.js (https://github.com/lovasoa/sql.js)

Jump to

Keyboard shortcuts

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