bindings

package
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: 4 Imported by: 0

README

This package provides minimal GopherJS bindings around SQL.js.

The SQL.js API is pretty simple to begin with, so the direct mapping to Go methods is also fairly straight forward.

Database object methods:

SQL.js go-sql.js
constructor New(), OpenReader()
exec Exec()
each --
prepare Prepare(), PrepareParams()
export Export()
close Close()
getRowsModified GetRowsModified()
create_function --

Statement object methods:

SQL.js go-sql.js
bind Bind(), BindNamed()
step Step()
get Get(), GetParams(), GetNamedParams()
getColumnNames GetColumnNames()
getAsObject GetAsMap(), GetAsMapParams(), GetAsMapNamedParams()
run Run()
reset Reset()
freemem Freemem()
free Free()

Documentation

Rendered for js/wasm

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	*js.Object
}

func New

func New() *Database

New returns a new database by creating a new one in memory

See http://lovasoa.github.io/sql.js/documentation/class/Database.html#constructor-dynamic

func OpenReader

func OpenReader(r io.Reader) *Database

OpenReader opens an existing database, referenced by the passed io.Reader

See http://lovasoa.github.io/sql.js/documentation/class/Database.html#constructor-dynamic

func (*Database) Close

func (d *Database) Close() (e error)

Close the database and all associated prepared statements.

See http://kripken.github.io/sql.js/documentation/class/Database.html#close-dynamic

func (*Database) Exec

func (d *Database) Exec(query string) (r []Result, e error)

Exec will execute an SQL query, and return the result.

This is a wrapper around Database.Prepare(), Statement.Step(), Statement.Get(), and Statement.Free().

The result is an array of Result elements. There are as many result elements as the number of statements in your sql string (statements are separated by a semicolon).

See http://kripken.github.io/sql.js/documentation/class/Database.html#exec-dynamic

func (*Database) Export

func (d *Database) Export() io.Reader

Export the contents of the database to an io.Reader

See http://kripken.github.io/sql.js/documentation/class/Database.html#export-dynamic

func (*Database) GetRowsModified

func (d *Database) GetRowsModified() int64

GetRowsModified returns the number of rows modified, inserted or deleted by the most recently completed INSERT, UPDATE or DELETE statement. Executing any other type of SQL statement does not modify the value returned by this function.

See http://kripken.github.io/sql.js/documentation/class/Database.html#getRowsModified-dynamic

func (*Database) Prepare

func (d *Database) Prepare(query string) (s *Statement, e error)

Prepare an SQL statement

See http://kripken.github.io/sql.js/documentation/class/Database.html#prepare-dynamic

func (*Database) PrepareNamedParams

func (d *Database) PrepareNamedParams(query string, params map[string]interface{}) (s *Statement, e error)

Prepare an SQL statement, with named parameters

See http://kripken.github.io/sql.js/documentation/class/Database.html#prepare-dynamic

func (*Database) PrepareParams

func (d *Database) PrepareParams(query string, params []interface{}) (s *Statement, e error)

Prepare an SQL statement, with array of parameters

See http://kripken.github.io/sql.js/documentation/class/Database.html#prepare-dynamic

func (*Database) Run

func (d *Database) Run(query string) (e error)

Run will execute one or more SQL queries (separated by ';'), ignoring the rows it returns

See http://kripken.github.io/sql.js/documentation/class/Database.html#run-dynamic

func (*Database) RunParams

func (d *Database) RunParams(query string, params []interface{}) (e error)

RunParams will execute a single SQL query, along with placeholder parameters, ignoring what it returns

See http://kripken.github.io/sql.js/documentation/class/Database.html#run-dynamic

type Result

type Result struct {
	Columns []string
	Values  [][]interface{}
}

type Statement

type Statement struct {
	*js.Object
}

func (*Statement) Bind

func (s *Statement) Bind(params []interface{}) (e error)

Bind values to parameters, after having reset the statement.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#bind-dynamic

func (*Statement) BindNamed

func (s *Statement) BindNamed(params map[string]interface{}) (e error)

BindNamed binds values to named parameters, after having reset the statement.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#bind-dynamic

func (*Statement) Free

func (s *Statement) Free() bool

Free frees any memory used by the statement.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#free-dynamic

func (*Statement) Freemem

func (s *Statement) Freemem()

Freemem frees memory allocated during paramater binding.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#freemem-dynamic

func (*Statement) Get

func (s *Statement) Get() (r []interface{}, e error)

Get one row of results of a statement. Step() must have been called first.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#get-dynamic

func (*Statement) GetAsMap

func (s *Statement) GetAsMap() (m map[string]interface{}, e error)

GetAsMap will get one row of result as a javascript object, associating column names with their value in the current row.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#getAsObject-dynamic

func (*Statement) GetAsMapNamedParams

func (s *Statement) GetAsMapNamedParams(params map[string]interface{}) (m map[string]interface{}, e error)

GetAsMapNamedParams will get one row of result as a javascript object, associating column names with their value in the current row, after binding the parameters and executing the statement

See http://kripken.github.io/sql.js/documentation/class/Statement.html#getAsObject-dynamic

func (*Statement) GetAsMapParams

func (s *Statement) GetAsMapParams(params []interface{}) (m map[string]interface{}, e error)

GetAsMapParams will get one row of result as a javascript object, associating column names with their value in the current row, after binding the parameters and executing the statement

See http://kripken.github.io/sql.js/documentation/class/Statement.html#getAsObject-dynamic

func (*Statement) GetColumnNames

func (s *Statement) GetColumnNames() (c []string, e error)

GetColumnNames list of column names of a row of result of a statement.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#getColumnNames-dynamic

func (*Statement) GetNamedParams

func (s *Statement) GetNamedParams(params map[string]interface{}) (r []interface{}, e error)

GetNamedParams will get one row of results of a statement after binding the parameters and executing the statement.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#get-dynamic

func (*Statement) GetParams

func (s *Statement) GetParams(params []interface{}) (r []interface{}, e error)

GetParams will get one row of results of a statement after binding the parameters and executing the statement.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#get-dynamic

func (*Statement) Reset

func (s *Statement) Reset()

Reset a statement, so that it's parameters can be bound to new values. It also clears all previous bindings, freeing the memory used by bound parameters.

See http://kripken.github.io/sql.js/documentation/class/Statement.html#reset-dynamic

func (*Statement) Run

func (s *Statement) Run() (e error)

Run is shorthand for Bind() + Step() + Reset(). Bind the values, execute the statement, ignoring the rows it returns, and resets it

See http://kripken.github.io/sql.js/documentation/class/Statement.html#run-dynamic

func (*Statement) RunNamedParams

func (s *Statement) RunNamedParams(params map[string]interface{}) (e error)

RunNamedParams is shorthand for Bind() + Step() + Reset(). Bind the values, execute the statement, ignoring the rows it returns, and resets it

See http://kripken.github.io/sql.js/documentation/class/Statement.html#run-dynamic

func (*Statement) RunParams

func (s *Statement) RunParams(params []interface{}) (e error)

RunParams is shorthand for Bind() + Step() + Reset(). Bind the values, execute the statement, ignoring the rows it returns, and resets it

See http://kripken.github.io/sql.js/documentation/class/Statement.html#run-dynamic

func (*Statement) Step

func (s *Statement) Step() (ok bool, e error)

Step executes the statement if necessary, and fetches the next line of the result which can be retrieved with Get().

See http://kripken.github.io/sql.js/documentation/class/Statement.html#step-dynamic

Jump to

Keyboard shortcuts

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