Skip to content

Commit c41ff35

Browse files
committed
add OOP style, authorization support, resolve space and fields names
1 parent 05d2eb0 commit c41ff35

File tree

3 files changed

+428
-185
lines changed

3 files changed

+428
-185
lines changed

README.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,36 @@ Synopsis
1515

1616
```lua
1717

18-
local tarantool = require("tarantool")
19-
20-
local host = "127.0.0.1"
21-
local port = 3301
22-
local spaceno = 1
23-
local indexno = 0
24-
local key = { 1 }
25-
local tuple = { "first field", "second field" }
26-
27-
local result, err = tarantool.select(host, port, spaceno, indexno, key)
28-
29-
local result, err = tarantool.insert(host, port, spaceno, tuple)
30-
31-
local result, err = tarantool.replace(host, port, spaceno, tuple)
32-
33-
local result, err = tarantool.delete(host, port, spaceno, key)
34-
35-
local result, err = tarantool.ping(host, port)
36-
37-
local result, err = tarantool.call(host, port, "proc_name", { "first arg" })
18+
tarantool = require("tarantool")
19+
20+
-- initialize connection
21+
local tar, err = tarantool:new()
22+
23+
local tar, err = tarantool:new({ connect_now = false })
24+
local ok, err = tar:connect()
25+
26+
local tar, err = tarantool:new({
27+
host = '127.0.0.1',
28+
port = 3301,
29+
user = 'gg_tester',
30+
password = 'pass',
31+
socket_timeout = 2000,
32+
connect_now = true,
33+
})
34+
35+
-- requests
36+
local data, err = tar:ping()
37+
local data, err = tar:insert('profiles', { 1, "nick 1" })
38+
local data, err = tar:insert('profiles', { 2, "nick 2" })
39+
local data, err = tar:select(2, 0, 3)
40+
local data, err = tar:select('profiles', 'uid', 3)
41+
local data, err = tar:replace('profiles', {3, "nick 33"})
42+
local data, err = tar:delete('profiles', 3)
43+
local data, err = tar:update('profiles', 'uid', 3, {{ '=', 1, 'nick new' }})
44+
local data, err = tar:update('profiles', 'uid', 3, {{ '#', 1, 1 }})
45+
46+
-- disconnect or set_keepalive at the end
47+
local ok, err = tar:disconnect()
48+
local ok, err = tar:set_keepalive()
3849

3950
```

const.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module("const", package.seeall)
2+
3+
-- common
4+
GREETING_SIZE = 128
5+
GREETING_SALT_OFFSET = 64
6+
GREETING_SALT_SIZE = 44
7+
HEAD_BODY_LEN_SIZE = 5
8+
REQUEST_PER_CONNECTION = 100000
9+
MAX_LIMIT = 0xFFFFFFFF
10+
11+
-- default options
12+
HOST = '127.0.0.1'
13+
PORT = 3301
14+
USER = false
15+
PASSWORD = ''
16+
SOCKET_TIMEOUT = 5000
17+
CONNECT_NOW = true
18+
19+
-- packet codes
20+
OK = 0
21+
SELECT = 1
22+
INSERT = 2
23+
REPLACE = 3
24+
UPDATE = 4
25+
DELETE = 5
26+
CALL = 6
27+
AUTH = 7
28+
PING = 64
29+
ERROR_TYPE = 65536
30+
31+
-- packet keys
32+
TYPE = 0x00
33+
SYNC = 0x01
34+
SPACE_ID = 0x10
35+
INDEX_ID = 0x11
36+
LIMIT = 0x12
37+
OFFSET = 0x13
38+
ITERATOR = 0x14
39+
KEY = 0x20
40+
TUPLE = 0x21
41+
FUNCTION_NAME = 0x22
42+
USER_NAME = 0x23
43+
DATA = 0x30
44+
ERROR = 0x31
45+
46+
-- default spaces
47+
SPACE_SCHEMA = 272
48+
SPACE_SPACE = 280
49+
SPACE_INDEX = 288
50+
SPACE_FUNC = 296
51+
SPACE_USER = 304
52+
SPACE_PRIV = 312
53+
SPACE_CLUSTER = 320
54+
55+
-- index info
56+
INDEX_SPACE_PRIMARY = 0
57+
INDEX_SPACE_NAME = 2
58+
INDEX_INDEX_PRIMARY = 0
59+
INDEX_INDEX_NAME = 2

0 commit comments

Comments
 (0)