|
| 1 | +net_box = require('net.box') |
| 2 | +--[[ |
| 3 | +--- |
| 4 | +... |
| 5 | +]] |
| 6 | + |
| 7 | +conn = net_box. connect( 'sampleuser:[email protected]:3301') |
| 8 | +--[[ |
| 9 | +--- |
| 10 | +... |
| 11 | +]] |
| 12 | + |
| 13 | +conn:ping() |
| 14 | +--[[ |
| 15 | +--- |
| 16 | +- true |
| 17 | +... |
| 18 | +]] |
| 19 | + |
| 20 | +function net_box_data_operations() |
| 21 | + -- Start net.box session |
| 22 | + conn.space.bands:insert({ 1, 'Roxette', 1986 }) |
| 23 | + --[[ |
| 24 | + --- |
| 25 | + - - [1, 'Roxette', 1986] |
| 26 | + ... |
| 27 | + ]] |
| 28 | + conn.space.bands:insert({ 2, 'Scorpions', 1965 }) |
| 29 | + --[[ |
| 30 | + --- |
| 31 | + - [2, 'Scorpions', 1965] |
| 32 | + ... |
| 33 | + ]] |
| 34 | + conn.space.bands:insert({ 3, 'Ace of Base', 1987 }) |
| 35 | + --[[ |
| 36 | + --- |
| 37 | + - [3, 'Ace of Base', 1987] |
| 38 | + ... |
| 39 | + ]] |
| 40 | + conn.space.bands:insert({ 4, 'The Beatles', 1960 }) |
| 41 | + --[[ |
| 42 | + --- |
| 43 | + - [4, 'The Beatles', 1960] |
| 44 | + ... |
| 45 | + ]] |
| 46 | + |
| 47 | + conn.space.bands:select({ 1 }) |
| 48 | + --[[ |
| 49 | + --- |
| 50 | + - - [1, 'Roxette', 1986] |
| 51 | + ... |
| 52 | + ]] |
| 53 | + |
| 54 | + conn.space.bands.index.band:select({ 'The Beatles' }) |
| 55 | + --[[ |
| 56 | + --- |
| 57 | + - - [4, 'The Beatles', 1960] |
| 58 | + ... |
| 59 | + ]] |
| 60 | + |
| 61 | + conn.space.bands:update({ 2 }, { { '=', 'band_name', 'Pink Floyd' } }) |
| 62 | + --[[ |
| 63 | + --- |
| 64 | + - [2, 'Pink Floyd', 1965] |
| 65 | + ... |
| 66 | + ]] |
| 67 | + |
| 68 | + conn.space.bands:upsert({ 5, 'The Rolling Stones', 1962 }, { { '=', 'band_name', 'The Doors' } }) |
| 69 | + --[[ |
| 70 | + --- |
| 71 | + ... |
| 72 | + ]] |
| 73 | + |
| 74 | + conn.space.bands:replace({ 1, 'Queen', 1970 }) |
| 75 | + --[[ |
| 76 | + --- |
| 77 | + - [1, 'Queen', 1970] |
| 78 | + ... |
| 79 | + ]] |
| 80 | + |
| 81 | + conn.space.bands:delete({ 5 }) |
| 82 | + --[[ |
| 83 | + --- |
| 84 | + - [5, 'The Rolling Stones', 1962] |
| 85 | + ... |
| 86 | + ]] |
| 87 | + |
| 88 | + conn:call('get_bands_older_than', { 1966 }) |
| 89 | + -- --- |
| 90 | + -- - [[2, 'Pink Floyd', 1965], [4, 'The Beatles', 1960]] |
| 91 | + -- ... |
| 92 | + -- End net.box session |
| 93 | +end |
| 94 | + |
| 95 | +function net_box_close_connection() |
| 96 | + conn:close() |
| 97 | + --[[ |
| 98 | + --- |
| 99 | + ... |
| 100 | + ]] |
| 101 | + -- Close net.box connection |
| 102 | +end |
0 commit comments