Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction support #17

Merged
merged 1 commit into from
Jul 8, 2018
Merged

Transaction support #17

merged 1 commit into from
Jul 8, 2018

Conversation

vonagam
Copy link
Contributor

@vonagam vonagam commented Jul 8, 2018

Support transactions with same format as feathers-knex (params.transaction.trx).

Hooks can easily be moved too (mainly this line need change from Model.transaction to Model.knex().transaction and removal of debug lines), but i do not have tests for them.

it('works with commit', () => {
return people.create({name: 'Commit'}, {transaction}).then(() => {
return transaction.trx.commit().then(() => {
return people.find({ query: { name: 'Commit' } }).then((data) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would also want to check that the data isn't saved in the database before the commit.

Copy link
Contributor Author

@vonagam vonagam Jul 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, tried to add checks for this. There is a problem.
You need to have multiple connections to db for that.
And sqlite have problems with it: 1, 2.
Simple addition of pool: { min: 2, max: 2 } makes tests on my machine run 14s against usual 4s and sometimes some random test will fail with "database is locked"...

So it seems it does not worth the trouble, but just to be clear this one is passing with pool 2:

it('works with commit', () => {
  return people.create({ name: 'Commit' }, { transaction }).then((data) => {
    return people.find({ query: { name: 'Commit' } }).then((data) => expect(data.length).to.equal(0)).then(() => {
      return transaction.trx.commit().then(() => {
        return people.find({ query: { name: 'Commit' } }).then((data) => expect(data.length).to.equal(1))
      })
    })
  })
})

Copy link
Member

@mcchrish mcchrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcchrish mcchrish merged commit 9f1092f into feathersjs-ecosystem:master Jul 8, 2018
@vonagam vonagam mentioned this pull request Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants