Skip to content

Spacer for Tarantool. For managing spaces easily.

License

Notifications You must be signed in to change notification settings

moonlibs/spacer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THIS IS AN OLD UNMAINTAINED VERSION OF SPACER. PLEASE USE igorcoding/tarantool-spacer.

tarantool-spacer

Spacer for Tarantool. For managing spaces easily.

Usage examples

spacer.create_space('space1', {
    { name='id', type='unsigned' },
    { name='name', type='string' },
    { name='type', type='string' },
    { name='status', type='string' },
    { name='extra', type='*' },  -- * just a stub for practically any type
    
}, {
    { name = 'primary', type = 'hash', parts = { 'id' } },
    { name = 'type', type = 'tree', unique = false, parts = { 'type', 'status' } },
})

-- space3 will be identical to space1 (structure + indexes)
spacer.duplicate_space('space3', 'space1')

-- space4 will be identical to space1 (structure + indexes, extra indexes will be created)
spacer.duplicate_space('space4', 'space1', {
    indexes = {
        { name = 'status', type = 'tree', unique = false, parts = { 'status' } },
    }
})

-- space5 will be identical to space1 (only structure, indexes will be omitted)
spacer.duplicate_space('space5', 'space1', {
    dupindex = false
})

-- space6 will be identical to space1 (only structure, indexes will be omitted, extra indexes will be created)
spacer.duplicate_space('space6', 'space1', {
    dupindex = false,
    indexes = {
        { name = 'status', type = 'tree', unique = false, parts = { 'status' } },
    }
})

-- vy_space1 will be identical to space1 (but in engine = 'vinyl')
spacer.duplicate_space('vy_space1', 'space1', {
    engine = 'vinyl'
})

Fields

Space fields can be accessed by the global variable F:

box.space.space1:update(
    {1},
    {
        {'=', F.space1.name, 'John Watson'},
        {'=', F.space1.type, 'Doctor'},
    }
)

Transofrmations

You can easily transform a given tuple to a dictionary-like object and vice-a-versa.

These are the functions:

  • T.space_name.dict or T.space_name.hash - transforms a tuple to a dictionary
  • T.space_name.tuple - transforms a dictionary back to a tuple
local john = box.space.space1:get({1})
local john_dict = T.space1.dict(john) -- or hash() function
--[[
john_dict = {
    id = 1,
    name = 'John Watson',
    type = 'Doctor',
    ...
}
--]]

... or vice-a-versa:

local john_dict = {
    id = 1,
    name = 'John Watson',
    type = 'Doctor',
    -- ...
}

local john = T.space1.tuple(john_dict)
--[[
john = [1, 'John Watson', 'Doctor', ...]
--]]

About

Spacer for Tarantool. For managing spaces easily.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%