Coder Social home page Coder Social logo

Comments (7)

gr0uch avatar gr0uch commented on June 8, 2024

The code for deletion is very simple, so simple that I wouldn't really know where the problem is:

delete (type, ids) {
if (ids && !ids.length) return super.delete()
const Promise = this.Promise
const client = this.client
const typeMap = this.options.typeMap
const primaryKey = this.keys.primary
let index = 0
/* eslint-disable prefer-template */
const deleteRecords =
`delete from "${typeMap[type] || type}"` +
(ids ? ` where "${primaryKey}" in ` +
`(${ids.map(() => {
index++
return `$${index}`
}).join(', ')})` : '')
/* eslint-enable prefer-template */
return new Promise((resolve, reject) =>
client.query(deleteRecords, ids ? ids : null,
(error, result) => error ? reject(error) : resolve(result.rowCount)))
}

Maybe you can confirm that this is the case by adding a find before you got the ConflictError?

from fortune-postgres.

gr0uch avatar gr0uch commented on June 8, 2024

Also the test for the adapter does create immediately after delete: https://github.com/fortunejs/fortune/blob/44e0469e9c81516c96066b9fcea2607900ee0397/test/unit/adapter.js#L584-L585

from fortune-postgres.

thomasthiebaud avatar thomasthiebaud commented on June 8, 2024

Ok, so I add a find before using delete like this

beforeEach(function () {
    return store.adapter.find('user').then((res) => {
      console.log('RES')
      console.log(res)
      return database.truncate()
    });
  });

I get this output

RES
[ count: 0 ]

So there is not user. BUT if I go check in the database, there is one user (added throw fortunejs)

from fortune-postgres.

thomasthiebaud avatar thomasthiebaud commented on June 8, 2024

If I'm switching from

function truncate() {
  return store.adapter.delete('user')
      .then(() => store.adapter.delete('customer'));
}

to

function truncate() {
  return store.adapter.delete('customer')
      .then(() => store.adapter.delete('user'));
}

I not longer have the error, but I don't know why

from fortune-postgres.

gr0uch avatar gr0uch commented on June 8, 2024

Hmm, I'm not sure where the problem is, since the tests for this adapter seem to do what you're trying to do without error.

Basically this should work:

return adapter.delete(type)
.then(() => adapter.create(type, records))

If that doesn't work then it would be a problem here.

from fortune-postgres.

thomasthiebaud avatar thomasthiebaud commented on June 8, 2024

Ok I found why :

  • I was mixing store.XYZ and store.adapter.XYZ
  • When you create a record using store.adapter.create(type, records), records MUST be an array. Otherwise it will only call return new Promise().resolve()
  • When adding data using store.adapter.create you have to manually insert relationship both in each parts. So in my case I had to put the customer id in user.customer and push the user id in the customer.users

from fortune-postgres.

gr0uch avatar gr0uch commented on June 8, 2024

Yup, Fortune.js handles relationships but the adapter doesn't.

from fortune-postgres.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.