Skip to content

Instantly share code, notes, and snippets.

@ochaton
Created November 14, 2020 12:31
Show Gist options
  • Select an option

  • Save ochaton/eea0cf0e5a3054e0a916699b2d24574f to your computer and use it in GitHub Desktop.

Select an option

Save ochaton/eea0cf0e5a3054e0a916699b2d24574f to your computer and use it in GitHub Desktop.
Tarantool ORM interface
box.orm = require 'orm' . configure {
users = {
format = {
{ name = 'uid', type = 'unsigned' },
{ name = 'email', type = 'string' },
},
indexes = {
{ name = 'primary', parts = { 'uid' } },
{ name = 'email', parts = { 'email', 'uid' } },
},
class = require 'User',
},
accounts = {
format = {
{ name = 'id', type = 'string' },
{ name = 'user', type = 'unsigned' },
{ name = 'balance', type = 'unsigned' },
{ name = 'flags', type = 'unsigned' },
},
indexes = {
{ name = 'primary', parts = { 'id' } },
{ name = 'user', parts = { 'user', 'id' } },
},
fk = {
user = 'uid@users',
},
class = require 'Account',
},
transactions = {
format = {
{ name = 'id', type = 'string' },
{ name = 'account', type = 'string' },
{ name = 'iid', type = 'string' }, -- external ID
{ name = 'amount', type = 'unsigned' },
{ name = 'currency', type = 'string' },
{ name = 'status', type = 'string' },
},
indexes = {
{ name = 'primary', parts = { 'id' } },
{ name = 'iid', parts = { 'iid' } },
{ name = 'account', parts = { 'account', 'id' } },
{ name = 'account_status', parts = { 'account', 'status', 'id' } },
},
fk = {
account = 'id@accounts',
},
class = require 'Transaction',
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment