Skip to content

Function UpdateOrCreate

update or create on different connection

typescript
await FedacoTestUser.createQuery().create({
  email: 'linbolen@gradii.com'
});
await FedacoTestUser.useConnection('second_connection').updateOrCreate(
  {
    email: 'linbolen@gradii.com'
  },
  {
    name: 'Taylor Otwell'
  }
);
await FedacoTestUser.useConnection('second_connection').updateOrCreate(
  {
    email: 'tony.stark@gradii.com'
  },
  {
    name: 'Mohamed Said'
  }
);
ReferenceLooks LikeValue
await FedacoTestUser.useConnection('second_connection').count()exactly match2

see also prerequisites

update or create

typescript
const user1 = await FedacoTestUser.createQuery().create({
  email: 'linbolen@gradii.com'
});
const user2 = await FedacoTestUser.createQuery().updateOrCreate(
  {
    email: 'linbolen@gradii.com'
  },
  {
    name: 'Taylor Otwell'
  }
);
ReferenceLooks LikeValue
user2.emailexactly match'linbolen@gradii.com'
user2.nameexactly match'Taylor Otwell'
ReferenceLooks LikeValue
user3.nameexactly match'Mohamed Said'
await FedacoTestUser.createQuery().count()exactly match2

see also prerequisites

Released under the MIT License.