Skip to content

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

License

Notifications You must be signed in to change notification settings

teejaded/gluasql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LuaSql for GopherLua

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

Using

Loading Modules

import (
	"github.com/tengattack/gluasql"
)

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

// Preload LuaSql modules
gluasocket.Preload(L)

Or if we only need mysql module:

import (
	mysql "github.com/tengattack/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

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/tengattack/gluasql...
?       github.com/tengattack/gluasql   [no test files]
ok      github.com/tengattack/gluasql/mysql     1.135s  coverage: 73.7% of statements
ok      github.com/tengattack/gluasql/sqlite3   0.098s  coverage: 71.3% of statements
ok      github.com/tengattack/gluasql/util      0.072s  coverage: 76.9% of statements

License

MIT

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%