https://github.com/tarantool/tarantool-lua
Tarantool connector for Lua
https://github.com/tarantool/tarantool-lua
Last synced: about 1 year ago
JSON representation
Tarantool connector for Lua
- Host: GitHub
- URL: https://github.com/tarantool/tarantool-lua
- Owner: tarantool
- License: bsd-2-clause
- Created: 2013-09-20T14:48:22.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2022-11-23T23:28:48.000Z (over 3 years ago)
- Last Synced: 2025-04-14T15:12:50.197Z (about 1 year ago)
- Language: Lua
- Size: 349 KB
- Stars: 33
- Watchers: 38
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
lua-tarantool-client
===================
Driver for tarantool 1.7 on nginx cosockets and plain lua sockets
Introduction
------------
A pure Lua driver for the NoSQL database [Tarantool](http://tarantool.org/) using fast nginx cosockets when available, or [luasocket](https://github.com/diegonehab/luasocket) as a fallback.
Requires [lua-MessagePack](https://github.com/fperrad/lua-MessagePack).
luasock
-------
For `luasock` sockets, [lua-resty-socket](https://github.com/thibaultcha/lua-resty-socket) and [sha1.lua](https://github.com/kikito/sha1.lua) are required.
These can be installed using `luarocks install lua-resty-socket` and `luarocks install sha1`
Synopsis
------------
```lua
tarantool = require("tarantool")
-- initialize connection
local tar = tarantool({
host = '127.0.0.1',
port = 3301,
user = 'gg_tester',
password = 'pass',
socket_timeout = 2000,
connect_now = true,
})
-- requests
local data, err = tar:ping()
local data, err = tar:insert('profiles', { 1, "nick 1" })
local data, err = tar:insert('profiles', { 2, "nick 2" })
local data, err = tar:select(2, 0, 3)
local data, err = tar:select('profiles', 'uid', 3)
local data, err = tar:replace('profiles', {3, "nick 33"})
local data, err = tar:delete('profiles', 3)
local data, err = tar:update('profiles', 'uid', 3, {{ '=', 1, 'nick new' }})
local data, err = tar:update('profiles', 'uid', 3, {{ '#', 1, 1 }})
-- disconnect or set_keepalive at the end
local ok, err = tar:disconnect()
local ok, err = tar:set_keepalive()
```
Hacking
-------
Module contains implementations written in Lua and
[Moonscript][moonscript-url]. First one could be generated using second one
using the Moonscript compiler:
```sh
$ luarocks --local install moonscript
$ export PATH=$PATH:$(luarocks path --lr-bin)
$ moonc -o tarantool.lua tarantool.moon
```
[moonscript-url]: https://moonscript.org/