-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb2e255
commit 16ccbe2
Showing
13 changed files
with
532 additions
and
323 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
doc/code_snippets/snippets/config/instances.enabled/create_db/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Creating your first Tarantool database | ||
|
||
A sample application created in the [Creating your first Tarantool database](https://www.tarantool.io/en/doc/latest/how-to/getting_started_db/) tutorial. | ||
|
||
## Running | ||
|
||
To start an instance, execute the following command in the [config](../../../config) directory: | ||
|
||
```console | ||
$ tt start create_db | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ groups: | |
instance001: | ||
iproto: | ||
listen: | ||
- uri: '127.0.0.1:3301' | ||
- uri: '127.0.0.1:3301' |
29 changes: 0 additions & 29 deletions
29
doc/code_snippets/snippets/config/instances.enabled/create_db/myapp.lua
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
doc/code_snippets/snippets/connectors/instances.enabled/sample_db/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Connectors | ||
|
||
A sample application used to demonstrate how to connect to a database using connectors for different languages and execute requests for manipulating the data. | ||
|
||
## Running | ||
|
||
Start the application by executing the following command in the [connectors](../../../connectors) directory: | ||
|
||
```console | ||
$ tt start sample_db | ||
``` |
22 changes: 22 additions & 0 deletions
22
doc/code_snippets/snippets/connectors/instances.enabled/sample_db/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
credentials: | ||
users: | ||
sampleuser: | ||
password: '123456' | ||
privileges: | ||
- permissions: [ read, write ] | ||
spaces: [ bands ] | ||
- permissions: [ execute ] | ||
functions: [ get_bands_older_than ] | ||
|
||
groups: | ||
group001: | ||
replicasets: | ||
replicaset001: | ||
instances: | ||
instance001: | ||
iproto: | ||
listen: | ||
- uri: '127.0.0.1:3301' | ||
|
||
app: | ||
file: 'myapp.lua' |
1 change: 1 addition & 0 deletions
1
doc/code_snippets/snippets/connectors/instances.enabled/sample_db/instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
instance001: |
23 changes: 23 additions & 0 deletions
23
doc/code_snippets/snippets/connectors/instances.enabled/sample_db/myapp.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Create a space -- | ||
box.schema.space.create('bands') | ||
|
||
-- Specify field names and types -- | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
|
||
-- Create indexes -- | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
box.space.bands:create_index('band', { parts = { 'band_name' } }) | ||
box.space.bands:create_index('year_band', { parts = { { 'year' }, { 'band_name' } } }) | ||
|
||
-- Create a stored function -- | ||
box.schema.func.create('get_bands_older_than', { | ||
body = [[ | ||
function(year) | ||
return box.space.bands.index.year_band:select({ year }, { iterator = 'LT', limit = 10 }) | ||
end | ||
]] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# net.box | ||
|
||
A sample application containing `net.box` requests from the [Getting started with net.box](https://www.tarantool.io/en/doc/latest/how-to/getting_started_net_box/) tutorial. | ||
|
||
|
||
## Running | ||
|
||
Before running this sample, start an application that allows remote connections to a sample database: [sample_db](../instances.enabled/sample_db). | ||
|
||
Then, start the interactive session by executing the following command in the [connectors](..) directory: | ||
|
||
```console | ||
$ tt run -i net_box/myapp.lua | ||
``` | ||
|
||
In the console, you can use the `conn` object to execute requests for manipulating the data. |
102 changes: 102 additions & 0 deletions
102
doc/code_snippets/snippets/connectors/net_box/myapp.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
net_box = require('net.box') | ||
--[[ | ||
--- | ||
... | ||
]] | ||
|
||
conn = net_box.connect('sampleuser:[email protected]:3301') | ||
--[[ | ||
--- | ||
... | ||
]] | ||
|
||
conn:ping() | ||
--[[ | ||
--- | ||
- true | ||
... | ||
]] | ||
|
||
function net_box_data_operations() | ||
-- Start net.box session | ||
conn.space.bands:insert({ 1, 'Roxette', 1986 }) | ||
--[[ | ||
--- | ||
- - [1, 'Roxette', 1986] | ||
... | ||
]] | ||
conn.space.bands:insert({ 2, 'Scorpions', 1965 }) | ||
--[[ | ||
--- | ||
- [2, 'Scorpions', 1965] | ||
... | ||
]] | ||
conn.space.bands:insert({ 3, 'Ace of Base', 1987 }) | ||
--[[ | ||
--- | ||
- [3, 'Ace of Base', 1987] | ||
... | ||
]] | ||
conn.space.bands:insert({ 4, 'The Beatles', 1960 }) | ||
--[[ | ||
--- | ||
- [4, 'The Beatles', 1960] | ||
... | ||
]] | ||
|
||
conn.space.bands:select({ 1 }) | ||
--[[ | ||
--- | ||
- - [1, 'Roxette', 1986] | ||
... | ||
]] | ||
|
||
conn.space.bands.index.band:select({ 'The Beatles' }) | ||
--[[ | ||
--- | ||
- - [4, 'The Beatles', 1960] | ||
... | ||
]] | ||
|
||
conn.space.bands:update({ 2 }, { { '=', 'band_name', 'Pink Floyd' } }) | ||
--[[ | ||
--- | ||
- [2, 'Pink Floyd', 1965] | ||
... | ||
]] | ||
|
||
conn.space.bands:upsert({ 5, 'The Rolling Stones', 1962 }, { { '=', 'band_name', 'The Doors' } }) | ||
--[[ | ||
--- | ||
... | ||
]] | ||
|
||
conn.space.bands:replace({ 1, 'Queen', 1970 }) | ||
--[[ | ||
--- | ||
- [1, 'Queen', 1970] | ||
... | ||
]] | ||
|
||
conn.space.bands:delete({ 5 }) | ||
--[[ | ||
--- | ||
- [5, 'The Rolling Stones', 1962] | ||
... | ||
]] | ||
|
||
conn:call('get_bands_older_than', { 1966 }) | ||
-- --- | ||
-- - [[2, 'Pink Floyd', 1965], [4, 'The Beatles', 1960]] | ||
-- ... | ||
-- End net.box session | ||
end | ||
|
||
function net_box_close_connection() | ||
conn:close() | ||
--[[ | ||
--- | ||
... | ||
]] | ||
-- Close net.box connection | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
modules: | ||
# Directory where the external modules are stored. | ||
directory: modules | ||
|
||
env: | ||
# Restart instance on failure. | ||
restart_on_failure: false | ||
|
||
# Directory that stores binary files. | ||
bin_dir: bin | ||
|
||
# Directory that stores Tarantool header files. | ||
inc_dir: include | ||
|
||
# Path to directory that stores all applications. | ||
# The directory can also contain symbolic links to applications. | ||
instances_enabled: instances.enabled | ||
|
||
# Tarantoolctl artifacts layout compatibility: if set to true tt will not create application | ||
# sub-directories for control socket, pid files, log files, etc.. Data files (wal, vinyl, | ||
# snap) and multi-instance applications are not affected by this option. | ||
tarantoolctl_layout: false | ||
|
||
app: | ||
# Directory that stores various instance runtime | ||
# artifacts like console socket, PID file, etc. | ||
run_dir: var/run | ||
|
||
# Directory that stores log files. | ||
log_dir: var/log | ||
|
||
# Directory where write-ahead log (.xlog) files are stored. | ||
wal_dir: var/lib | ||
|
||
# Directory where memtx stores snapshot (.snap) files. | ||
memtx_dir: var/lib | ||
|
||
# Directory where vinyl files or subdirectories will be stored. | ||
vinyl_dir: var/lib | ||
|
||
# Path to file with credentials for downloading Tarantool Enterprise Edition. | ||
# credential_path: /path/to/file | ||
ee: | ||
credential_path: | ||
|
||
templates: | ||
# The path to templates search directory. | ||
- path: templates | ||
|
||
repo: | ||
# Directory where local rocks files could be found. | ||
rocks: | ||
# Directory that stores installation files. | ||
distfiles: distfiles |
Oops, something went wrong.