PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

table name error #86

Closed xualen closed 5 years ago

xualen commented 5 years ago

Thanks for a great library. there is a table(admin) in mysql, i use "store.Model('admin');". node js log error "Error: ER_NO_SUCH_TABLE: Table 'test.admins' doesn't exist"

PhilWaldmann commented 5 years ago

Hi @xualen

thanks!

openrecord always pluralize model names to get the table name. In your case, you need to tell openrecord not to do so:

const store = new Store({
  // your config here...
  inflection: {
    'admins' : 'admin'
  }
})
xualen commented 5 years ago

@PhilWaldmann thanks. but i have a another question. is there transaction in openrecord?

PhilWaldmann commented 5 years ago

sure: https://openrecord.js.org/#/modify?id=transactions

xualen commented 5 years ago

@PhilWaldmann thank u. is openrecord support lock tables?

PhilWaldmann commented 5 years ago

not out of the box.

but it should be possible via:


await store.startTransaction(trx => {
  store.connection.transacting(trx).raw('LOCK TABLE...')
  .then(() => {
    ...
  })
})

The above code is not tested!! store.connection returns a knex instance. transacting and raw are knex functions!

let me know if that works for you.

Thanks, Philipp

xualen commented 5 years ago

@PhilWaldmann thanks for your answer.