• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / tarantool / 5867318873
88%

Build:
DEFAULT BRANCH: master
Ran 15 Aug 2023 01:05PM UTC
Jobs 1
Files 492
Run time 14s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

15 Aug 2023 12:55PM UTC coverage: 86.264% (+0.05%) from 86.219%
5867318873

push

github

alyapunov
box: support functional default field values

Now the default value of a tuple field can be computed as a result of a
function call.

Closes #8609

@TarantoolBot document
Title: Document functional default field values
Product: Tarantool
Since: 3.0
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/format/
Depends on: tarantool/doc#3520

The format clause contains, for each field, a definition within braces:
`{name='...',type='...'[,default=...][,default_func=...]}`,
where:

* (Optional) The `default_func` string value specifies the name of a
  function, that is used to generate a default value for the field. If
  `default_func` is set, the `default` value is used as the function
  argument. See [field default functions](https://www.tarantool.io/en/doc/latest/concepts/data_model/value_store/#field-default-functions).

---

Root document: https://www.tarantool.io/en/doc/latest/concepts/data_model/value_store/#constraint-functions

**Field default functions**

Stored Lua function can be used to generate a default value for the tuple
field. It can take one optional parameter, and must return exactly one
value. To create a field default function, use func.create with function
body. The function must not yield.

Example:

```lua
box.schema.func.create('random_point', {
    language = 'Lua',
    body = 'function(param) return math.random(param.min, param.max) end'
})

box.schema.space.create('test')
box.space.test:create_index('pk')
box.space.test:format({
    {name = 'id', type = 'integer'},
    {name = 'latitude', type = 'number',
     default_func = 'random_point', default = {min = -90, max = 90}},
    {name = 'longitude', type = 'number',
     default_func = 'random_point', default = {min = -180, max = 180}}
})
```

```lua
tarantool> math.randomseed(os.time())
---
...

tarantool> box.space.test:insert{1}
---
- [1, 56, 38]
...
```

63735 of 115343 branches covered (55.26%)

131 of 131 new or added lines in 7 files covered. (100.0%)

95434 of 110630 relevant lines covered (86.26%)

3122560.7 hits per line

Jobs
ID Job ID Ran Files Coverage
1 5867318873.1 15 Aug 2023 01:05PM UTC 0
86.26
GitHub Action Run
Source Files on build 5867318873
Detailed source file information is not available for this build.
  • Back to Repo
  • b055625f on github
  • Prev Build on master (#5866571931)
  • Next Build on master (#5876532745)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc