My database access functions contain various logic such as validation, error-throwing, and formatting logic. For example:async createItem(data) { const isValid = validate(data) is (!isValid) { throw new Error('invalid data'); } const input = convertToSnakeCase(data) input.id = uuid() await knex('items').insert(input) const retrieved = await knex('items').select('*').where('id', input.id) return convertToCamelCase(retrieved) } I also have other db functions that use multiple db functions which all currently run in sequence. I would like for them to run in a single transaction. Do knex transactions work well with code that has logic and throws errors?
Submitted June 15, 2020 at 11:40PM by izzlesnizzit
No comments:
Post a Comment