db

package
v0.0.0-...-f7fb57a Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

README

db GoDoc

Usage

local db = require("db")

local sqlite, err = db.open("sqlite3", "file:test.db?cache=shared&mode=memory")
if err then error(err) end

local result, err = sqlite:query("select 1")
if err then error(err) end
if not(result.rows[1][1] == 1) then error("sqlite error") end

local _, err = sqlite:exec("CREATE TABLE t (id int, name string);")
if err then error(err) end

for i = 1, 10 do
    local query = "INSERT INTO t VALUES ("..i..", \"name-"..i.."\");"
    if i % 2 == 0 then query = "INSERT INTO t VALUES ("..i..", NULL);" end
    local _, err = sqlite:exec(query)
    if err then error(err) end
end

local result, err = sqlite:query("select * from t;")
if err then error(err) end

for i, v in pairs(result.columns) do
    if i == 1 then if not(v == "id") then error("error") end end
    if i == 2 then if not(v == "name") then error("error") end end
end

for _, row in pairs(result.rows) do
    for id, name in pairs(result.columns) do
        print(name, row[id])
    end
end

local err = sqlite:close()
if err then error(err) end

Supported Drivers

Documentation

Overview

Package db implements golang package db functionality for lua.

Index

Constants

View Source
const (
	// max idle connections
	MaxIdleConns = 1
	// max open connections
	MaxOpenConns = 1
)

Variables

This section is empty.

Functions

func Close

func Close(L *lua.LState) int

Close(): lua db_ud:query(query) returns (table of tables, err)

func Exec

func Exec(L *lua.LState) int

Exec(): lua db_ud:exec(query) returns ({rows_affected=number, last_insert_id=number}, err)

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Open

func Open(L *lua.LState) int

Open(): lua db.open(driver, connection_string) returns (db_ud, err)

func Preload

func Preload(L *lua.LState)

Preload adds db to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local db = require("db")

func Query

func Query(L *lua.LState) int

Query(): lua db_ud:query(query) returns ({rows = {}, columns = {}}, err)

func RegisterDriver

func RegisterDriver(driver string, i luaDB)

RegisterDriver(): register sql driver

Types

This section is empty.

Jump to

Keyboard shortcuts

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