0.17.0 • Published 5 days ago

tarantoolscript v0.17.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

TarantoolScript

TarantoolScript is a tool to help you create Tarantool Lua scripts using TypeScript.

Getting started

To install Tarantoolscript add tarantoolscript npm package to your TypeScript project:

$ npm install --save-dev tarantoolscript

Also to compile your TypeScript program to Lua scripts, you need to install TypeScriptToLua:

$ npm install --save-dev typescript-to-lua

Here you can find more information about TypeScriptToLua.

Usage

Tarantoolscript provides some type declarations useful to create you own Lua scripts which may be executed by Tarantool. Here you can find more information about Tarantool.

Basic usage

Init instance

Interface Box describes all functions and submodules, included into Tarantool global variable box. To use it, just declare constant box of type Box:

import { Box, ConfigOptions } from 'tarantoolscript';

declare const box: Box;

const cfg: ConfigOptions = {
    listen: 3301,
};

box.cfg(cfg);

TypeScriptToLua will compile this TypeScript code to following Lua code:

local ____exports = {}
local cfg = {listen = 3301}
box.cfg(cfg)
return ____exports

Create space

const bands = box.schema.space.create('bands');

Format space

bands.format([
    { name: 'id', type: 'unsigned' },
    { name: 'band_name', type: 'string' },
    { name: 'year', type: 'unsigned' },
]);

Create index

bands.create_index('primary', { parts: ['id'] });

Insert data

bands.insert([1, 'Roxette', 1986]);

Tarantool modules usage

To usage some modules, which should be imported into script with Lua keyword require, you need first edit your tsconfig.json by following algorithm. At example, if you need to import module log, add it to tsconfig compilerOptions.paths:

{
    "compilerOptions": {
        "paths": {
            "log": ["tarantoolscript/src/log.d.ts"]
        }
    },
    "tstl": {
        "noResolvePaths": [
            "log"
        ]
    }
}

Or for module luatest.helpers:

{
    "compilerOptions": {
        "paths": {
            "luatest.helpers": ["tarantoolscript/src/luatest.helpers.d.ts"]
        }
    },
    "tstl": {
        "noResolvePaths": [
            "luatest.helpers"
        ]
    }
}

Now you can import and use these modules:

import * as log from 'log';
import * as luatest_helpers from 'luatest.helpers';

log.info(luatest_helpers.uuid(1, 2, 3));

After compilation:

local ____exports = {}
local log = require("log")
local luatest_helpers = require("luatest.helpers")
log.info(luatest_helpers.uuid(1, 2, 3))
return ____exports

Of course, to use luatest package or other packages which not included into Tarantool default build, you need to install them with tt rocks command.

More usage examples

This repository contains many useful samples, which are examples of using modules taken from the official Tarantool documentation. Every source file contains in its header link to the corresponding documentation page.

This repository can help you understanding how to write Tarantool scripts with TarantoolScript.

Status

Tarantoolscript is under development and not declares many useful Tarantool modules, which will be added in the near future.

Feel free to add Issue or create Pull request.

0.17.0

5 days ago

0.16.0

16 days ago

0.15.0

18 days ago

0.15.1

17 days ago

0.15.2

17 days ago

0.14.0

1 month ago

0.14.1

1 month ago

0.13.2

2 months ago

0.13.3

1 month ago

0.13.0

2 months ago

0.13.1

2 months ago

0.12.0

2 months ago

0.12.1

2 months ago

0.12.2

2 months ago

0.11.0

2 months ago

0.11.1

2 months ago

0.11.2

2 months ago

0.11.3

2 months ago

0.11.4

2 months ago

0.10.1

2 months ago

0.10.0

2 months ago

0.9.0

2 months ago

0.9.1

2 months ago

0.8.1

2 months ago

0.8.0

2 months ago

0.7.1

2 months ago

0.5.3

2 months ago

0.7.0

2 months ago

0.6.1

2 months ago

0.5.2

2 months ago

0.6.0

2 months ago

0.5.0

3 months ago

0.4.1

3 months ago

0.5.1

3 months ago

0.4.0

3 months ago

0.2.27

3 months ago

0.2.26

3 months ago

0.3.0

3 months ago

0.2.29

3 months ago

0.2.28

3 months ago

0.2.25

3 months ago

0.2.24

3 months ago

0.2.23

3 months ago

0.2.22

3 months ago

0.2.21

4 months ago

0.2.20

4 months ago

0.2.19

4 months ago

0.2.18

4 months ago

0.2.16

4 months ago

0.2.15

4 months ago

0.2.14

4 months ago

0.2.13

4 months ago

0.2.12

4 months ago

0.2.11

4 months ago

0.2.10

4 months ago

0.2.17

4 months ago

0.2.7

4 months ago

0.2.6

4 months ago

0.2.9

4 months ago

0.2.8

4 months ago

0.2.1

4 months ago

0.2.3

4 months ago

0.2.2

4 months ago

0.2.5

4 months ago

0.2.4

4 months ago

0.2.0

4 months ago

0.1.3

4 months ago

0.1.2

4 months ago

0.1.1

4 months ago

0.1.0

4 months ago