Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/config/pragmas/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ module.exports = function configureTables ({ arc, inventory, errors }) {
if (is.sortKey(value)) {
t.sortKey = key
t.sortKeyType = value.replace('**', '').toLowerCase()
if (t.sortKeyType === 'ttl') {
t.sortKeyType = 'number'
t.ttl = key
}
if (!t.sortKeyType) t.sortKeyType = 'string'
}
else if (is.primaryKey(value)) {
t.partitionKey = key
t.partitionKeyType = value.replace('*', '').toLowerCase()
if (t.partitionKeyType === 'ttl') {
t.partitionKeyType = 'number'
t.ttl = key
}
if (!t.partitionKeyType) t.partitionKeyType = 'string'
}
if (key === 'stream') t.stream = value
Expand Down
4 changes: 2 additions & 2 deletions src/lib/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let string = item => typeof item === 'string'
let exists = path => existsSync(path)
let folder = path => existsSync(path) && lstatSync(path).isDirectory()
// Pragma-specific stuff
let primaryKey = val => string(val) && [ '*', '*string', '*number' ].includes(val.toLowerCase())
let sortKey = val => string(val) && [ '**', '**string', '**number' ].includes(val.toLowerCase())
let primaryKey = val => string(val) && [ '*', '*string', '*number', '*ttl' ].includes(val.toLowerCase())
let sortKey = val => string(val) && [ '**', '**string', '**number', '**ttl' ].includes(val.toLowerCase())

module.exports = {
array,
Expand Down
27 changes: 26 additions & 1 deletion test/unit/src/config/pragmas/tables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ number-keys
})

test('@tables population (extra params)', t => {
t.plan(20)
t.plan(28)

let arc = parse(`
@tables
Expand Down Expand Up @@ -130,6 +130,31 @@ string-keys
tables = populateTables({ arc, inventory })
t.ok(tables.length === 1, 'Got correct number of tables back')
t.equal(tables[0].ttl, '_ttl', 'Got back correct TTL value')

arc = parse(`
@tables
time-to-live-primary
expiresAt *ttl
`)
inventory = inventoryDefaults()
tables = populateTables({ arc, inventory })
t.ok(tables.length === 1, 'Got correct number of tables back')
t.equal(tables[0].ttl, 'expiresAt', 'Got back correct TTL value')
t.equal(tables[0].partitionKey, 'expiresAt', 'Got back correct partition key')
t.equal(tables[0].partitionKeyType, 'Number', 'Got back correct partition key type')

arc = parse(`
@tables
time-to-live-secondary
pk *
expiresAt **ttl
`)
inventory = inventoryDefaults()
tables = populateTables({ arc, inventory })
t.ok(tables.length === 1, 'Got correct number of tables back')
t.equal(tables[0].ttl, 'expiresAt', 'Got back correct TTL value')
t.equal(tables[0].sortKey, 'expiresAt', 'Got back correct sort key')
t.equal(tables[0].sortKeyType, 'Number', 'Got back correct sort key type')
})

test('@tables population: plugin setter', t => {
Expand Down