gluasql

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

LuaSql for GopherLua

A native Go implementation of SQL client for the GopherLua VM.

Using

Loading Modules
import (
	"github.com/bbernhard/gluasql"
)

// Bring up a GopherLua VM
L := lua.NewState()
defer L.Close()

// Preload LuaSql modules
gluasql.Preload(L)

Or if we only need mysql module:

import (
	mysql "github.com/bbernhard/gluasql/mysql"
)

// Bring up a GopherLua VM
L := lua.NewState()
defer L.Close()

L.PreloadModule("mysql", mysql.Loader)
MySQL
mysql = require('mysql')
c = mysql.new()
ok, err = c:connect({ host = '127.0.0.1', port = 3306, database = 'test', user = 'user', password = 'pass' })
if ok then
  res, err = c:query('SELECT * FROM mytable LIMIT 2')
  dump(res)
end
PostgreSQL

import lib/pq first:

import (
	_ "github.com/lib/pq"
)
mysql = require('mysql')
c = mysql.new()
ok, err = c:connect('postgres://host=127.0.0.1 port=5432 user=user password=123456 dbname=foo sslmode=disable')
if ok then
  res, err = c:query('SELECT * FROM mytable LIMIT 2')
  dump(res)
end
SQLite

Since it depends go-sqlite3, we need gcc to compile SQLite module, more details: https://github.com/mattn/go-sqlite3

sqlite3 = require('sqlite3')
c = sqlite3.new()
ok, err = c:open('test.db', { cache = 'shared' })
if ok then
  res, err = c:query('SELECT * FROM mytable LIMIT 2')
  dump(res)
end

Testing

$ go test -coverprofile=/tmp/go-code-cover github.com/bbernhard/gluasql...
ok      github.com/bbernhard/gluasql/mysql     0.020s  coverage: 79.9% of statements
ok      github.com/bbernhard/gluasql/sqlite3   0.019s  coverage: 71.3% of statements
ok      github.com/bbernhard/gluasql/util      0.015s  coverage: 76.9% of statements

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preload

func Preload(L *lua.LState)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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