Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myselfghost/lua-resty-mysql-connector
Connection utilities for lua-resty-mysql,support for read and write separation,support for instantiating different databases
https://github.com/myselfghost/lua-resty-mysql-connector
Last synced: 3 months ago
JSON representation
Connection utilities for lua-resty-mysql,support for read and write separation,support for instantiating different databases
- Host: GitHub
- URL: https://github.com/myselfghost/lua-resty-mysql-connector
- Owner: myselfghost
- Created: 2018-04-18T08:26:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-18T08:46:36.000Z (over 6 years ago)
- Last Synced: 2024-02-14T18:34:39.707Z (9 months ago)
- Language: Lua
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-resty - lua-resty-mysql-connector
README
# lua-resty-mysql-connector
Connection utilities for lua-resty-mysql,support for read and write separation,support for instantiating different databases
# Methods## new
```
syntax: yourdb = db:new(database)
```
if there is not a database name, database = "default"```
local libmysql = require("libmysql")
local db_member = libmysql:new("member")
local db_test = libmysql:new()
```## query
```
syntax: res, err = yourdb:query("select des from test1 where test_id=? ", {3})
```
Some read database operations
## main
```
syntax: res, err = yourdb:main("UPDATE test1 SET des='my lua' WHERE test_id=?", {3})
```
Some write database operations# Synopsis
```
local libmysql = require("libmysql")
local db_member = libmysql:new("member")
local db_test = libmysql:new()local res, err = db_member:query("select des from test1 where (test_id=? )", {3})
if err or not res or type(res)~="table" or #res<1 then
ngx.say("test database member query :nothing")
else
ngx.say("test database member query :res")
endlocal res, err = db_test:query("select des from test1 where test_id=? ;", {3})
if err or not res or type(res)~="table" or #res<1 then
ngx.say("test database test query :nothing")
else
ngx.say("test database test query :res")
end
local res, err = db_test:main("UPDATE test1 SET des='my lua' WHERE test_id=?", {3})
```