Skip to content

Commit 336e8d8

Browse files
committed
Getting started: net.box
1 parent 9413c50 commit 336e8d8

File tree

10 files changed

+418
-101
lines changed

10 files changed

+418
-101
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# net.box
2+
3+
A sample application used to demonstrate the `net.box` API.
4+
5+
6+
## Running
7+
8+
Start the application by executing the following command in the [connectors](../../../connectors) directory:
9+
10+
```console
11+
$ tt start net_box
12+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
groups:
2+
group001:
3+
replicasets:
4+
replicaset001:
5+
instances:
6+
instance001:
7+
iproto: {}
8+
9+
app:
10+
file: 'myapp.lua'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
function net_box_session()
2+
local net_box = require('net.box')
3+
local conn = net_box.connect('sampleuser:[email protected]:3301')
4+
conn:ping()
5+
6+
conn.space.bands:insert { 1, 'Roxette', 1986 }
7+
conn.space.bands:insert { 2, 'Scorpions', 1965 }
8+
conn.space.bands:insert { 3, 'Ace of Base', 1987 }
9+
conn.space.bands:insert { 4, 'The Beatles', 1960 }
10+
--[[
11+
---
12+
...
13+
]]
14+
15+
conn.space.bands:select(1)
16+
--[[
17+
---
18+
- - [1, 'Roxette', 1986]
19+
...
20+
]]
21+
22+
conn.space.bands.index.band:select('The Beatles')
23+
--[[
24+
---
25+
- - [4, 'The Beatles', 1960]
26+
...
27+
]]
28+
29+
conn.space.bands:update({ 2 }, { { '=', 2, 'Pink Floyd' } })
30+
--[[
31+
---
32+
- [2, 'Pink Floyd', 1965]
33+
...
34+
]]
35+
36+
conn.space.bands:upsert({ 5, 'The Rolling Stones', 1962 }, { { '=', 2, 'The Doors' } })
37+
--[[
38+
---
39+
...
40+
]]
41+
42+
conn.space.bands:replace { 1, 'Queen', 1970 }
43+
--[[
44+
---
45+
- [1, 'Queen', 1970]
46+
...
47+
]]
48+
49+
conn.space.bands:delete(5)
50+
--[[
51+
---
52+
- [5, 'The Rolling Stones', 1962]
53+
...
54+
]]
55+
56+
conn:call('get_bands_older_than', { 1966 })
57+
-- ---
58+
-- - [[2, 'Pink Floyd', 1965], [4, 'The Beatles', 1960]]
59+
-- ...
60+
61+
conn:close()
62+
--[[
63+
---
64+
...
65+
]]
66+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Connectors
2+
3+
A sample application used to demonstrate how to connect to a database using connectors for different languages and execute requests for manipulating the data.
4+
5+
## Running
6+
7+
Start the application by executing the following command in the [connectors](../../../connectors) directory:
8+
9+
```console
10+
$ tt start sample_db
11+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
credentials:
2+
users:
3+
sampleuser:
4+
password: '123456'
5+
privileges:
6+
- permissions: [ read, write ]
7+
spaces: [ bands ]
8+
- permissions: [ execute ]
9+
functions: [ get_bands_older_than ]
10+
11+
groups:
12+
group001:
13+
replicasets:
14+
replicaset001:
15+
instances:
16+
instance001:
17+
iproto:
18+
listen:
19+
- uri: '127.0.0.1:3301'
20+
21+
app:
22+
file: 'myapp.lua'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Create a space --
2+
box.schema.space.create('bands')
3+
4+
-- Specify field names and types --
5+
box.space.bands:format({
6+
{ name = 'id', type = 'unsigned' },
7+
{ name = 'band_name', type = 'string' },
8+
{ name = 'year', type = 'unsigned' }
9+
})
10+
11+
-- Create indexes --
12+
box.space.bands:create_index('primary', { parts = { 'id' } })
13+
box.space.bands:create_index('band', { parts = { 'band_name' } })
14+
box.space.bands:create_index('year', { parts = { { 'year' } }, unique = false })
15+
box.space.bands:create_index('year_band', { parts = { { 'year' }, { 'band_name' } } })
16+
17+
-- Create a stored function --
18+
box.schema.func.create('get_bands_older_than', {
19+
body = [[
20+
function(year)
21+
return box.space.bands.index.year:select({ year }, { iterator = 'LT', limit = 10 })
22+
end
23+
]]
24+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
modules:
2+
# Directory where the external modules are stored.
3+
directory: modules
4+
5+
env:
6+
# Restart instance on failure.
7+
restart_on_failure: false
8+
9+
# Directory that stores binary files.
10+
bin_dir: bin
11+
12+
# Directory that stores Tarantool header files.
13+
inc_dir: include
14+
15+
# Path to directory that stores all applications.
16+
# The directory can also contain symbolic links to applications.
17+
instances_enabled: instances.enabled
18+
19+
# Tarantoolctl artifacts layout compatibility: if set to true tt will not create application
20+
# sub-directories for control socket, pid files, log files, etc.. Data files (wal, vinyl,
21+
# snap) and multi-instance applications are not affected by this option.
22+
tarantoolctl_layout: false
23+
24+
app:
25+
# Directory that stores various instance runtime
26+
# artifacts like console socket, PID file, etc.
27+
run_dir: var/run
28+
29+
# Directory that stores log files.
30+
log_dir: var/log
31+
32+
# Directory where write-ahead log (.xlog) files are stored.
33+
wal_dir: var/lib
34+
35+
# Directory where memtx stores snapshot (.snap) files.
36+
memtx_dir: var/lib
37+
38+
# Directory where vinyl files or subdirectories will be stored.
39+
vinyl_dir: var/lib
40+
41+
# Path to file with credentials for downloading Tarantool Enterprise Edition.
42+
# credential_path: /path/to/file
43+
ee:
44+
credential_path:
45+
46+
templates:
47+
# The path to templates search directory.
48+
- path: templates
49+
50+
repo:
51+
# Directory where local rocks files could be found.
52+
rocks:
53+
# Directory that stores installation files.
54+
distfiles: distfiles

0 commit comments

Comments
 (0)