Skip to content

Commit

Permalink
feat: code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-b committed Oct 24, 2023
1 parent e7729c2 commit 0c79416
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -3,13 +3,13 @@ const _ = require('lodash')
class GetCurrentValueFromSequence {
init (resourceConfig, env) {
this.id = `${_.snakeCase(resourceConfig.namespace)}.${_.snakeCase(resourceConfig.id)}`
this.prefix = resourceConfig.prefix || null
this.prefix = resourceConfig.prefix || ''
this.client = env.bootedServices.storage.client
}

async run (event, context) {
const value = await this.client.query(`SELECT last_value FROM ${this.id}`)
context.sendTaskSuccess({ value: (this.prefix ? `${this.prefix}${value.rows[0].last_value}` : value.rows[0].last_value) })
context.sendTaskSuccess({ value: `${this.prefix}${value.rows[0].last_value}` })
}
}

Expand Down
Expand Up @@ -3,13 +3,13 @@ const _ = require('lodash')
class GetNextValueFromSequence {
init (resourceConfig, env) {
this.id = `${_.snakeCase(resourceConfig.namespace)}.${_.snakeCase(resourceConfig.id)}`
this.prefix = resourceConfig.prefix || null
this.prefix = resourceConfig.prefix || ''
this.client = env.bootedServices.storage.client
}

async run (event, context) {
const value = await this.client.query(`select nextval('${this.id}')`)
context.sendTaskSuccess({ value: (this.prefix ? `${this.prefix}${value.rows[0].nextval}` : value.rows[0].nextval) })
context.sendTaskSuccess({ value: `${this.prefix}${value.rows[0].nextval}` })
}
}

Expand Down

0 comments on commit 0c79416

Please sign in to comment.