|
| 1 | +# ArangoDB Client for OpenResty |
| 2 | + |
1 | 3 | ### Dependencies
|
2 |
| - - lua-cjson |
3 |
| - - base64 |
4 |
| - - lua-resty-http |
5 | 4 |
|
6 |
| -### Testing |
| 5 | +- lua-cjson |
| 6 | +- base64 |
| 7 | +- lua-resty-http |
| 8 | + |
| 9 | +### Testing with resty utility |
| 10 | + |
| 11 | +1. Open a terminal window and navigate to your Lua script's directory. |
| 12 | +2. Run the command `resty resty [your lua script name]` to execute the script. |
| 13 | +3. If your Lua script requires any input or parameters, you can pass them as arguments after the script name. |
| 14 | +4. For example, if your lua script is named 'test.lua' and it takes in a parameter 'name', you can run the command.' |
| 15 | + `resty test.lua name=John`. |
| 16 | +5. The output of the script will be displayed in the terminal. |
| 17 | +6. You can also redirect the output to a file by using the '>' operator, for example, `resty /usr/local/bin/resty |
| 18 | + test.lua name=John > output.txt`. This will save the script's output in a file named 'output.txt'. |
| 19 | + |
| 20 | +**Example:** |
| 21 | + |
| 22 | +Create a Lua file, for example `test.lua`: |
| 23 | + |
| 24 | +```lua |
| 25 | +local arangodb = require("arangodb") |
| 26 | + |
| 27 | +local db = arangodb.new({ |
| 28 | + endpoint = "http://127.0.0.1:8529", |
| 29 | + username = "root", |
| 30 | + password = "openSesame", |
| 31 | + db = "debug" |
| 32 | +}) |
| 33 | + |
| 34 | +local success, results = pcall(function() |
| 35 | + return db:query("FOR i IN 1..10 RETURN i") |
| 36 | +end) |
| 37 | + |
| 38 | +if success then |
| 39 | + -- print the results |
| 40 | + for _, v in ipairs(results) do |
| 41 | + print(v) |
| 42 | + end |
| 43 | +else |
| 44 | + -- print the error message |
| 45 | + print(results) |
| 46 | +end |
| 47 | +``` |
| 48 | + |
| 49 | +Now you could run it just like this: |
| 50 | + |
| 51 | +```shell |
| 52 | +resty src/test.lua |
| 53 | +``` |
| 54 | + |
| 55 | +But because `arangodb` module is using few dependencies, you need to make sure they are installed: |
| 56 | + |
| 57 | +```shell |
| 58 | +luarocks install lua-cjson |
| 59 | +luarocks install lbase64 |
| 60 | +luarocks install lua-resty-http |
| 61 | +``` |
| 62 | + |
| 63 | +Then, when running with `resty` you need to provide the path to Lua libraries. |
| 64 | + |
| 65 | +To include libraries installed by luarocks in your Lua script, you need to add the following line at the top of your |
| 66 | +script |
| 67 | + |
| 68 | +```lua |
| 69 | +local luarocks_path = '/usr/local/share/lua/5.4/' |
| 70 | +package.path = package.path .. ";" .. luarocks_path .. "?.lua" |
| 71 | +``` |
7 | 72 |
|
| 73 | +Or run with `-I` argument pointing to luarocks libraries: |
8 | 74 | ```shell
|
9 | 75 | resty -I /usr/local/share/lua/5.4/ src/test.lua
|
10 | 76 | ```
|
0 commit comments