Skip to content

Function FirstOrNew

check and create methods on multi connections

typescript
await FedacoTestUser.createQuery().create({
  id: 1,
  email: 'linbolen@gradii.com'
});
await FedacoTestUser.useConnection('second_connection').find(
  FedacoTestUser.useConnection('second_connection').insert({
    id: 2,
    email: 'tony.stark@gradii.com'
  })
);
let user1 = await FedacoTestUser.useConnection('second_connection').findOrNew(
  1
);
let user2 = await FedacoTestUser.useConnection('second_connection').findOrNew(
  2
);
ReferenceLooks LikeValue
user2._existsexactly matchtrue
user1.getConnectionName()exactly match'second_connection'
user2.getConnectionName()exactly match'second_connection'
typescript
user2 = await FedacoTestUser.useConnection('second_connection').firstOrNew({
  email: 'tony.stark@gradii.com'
});
ReferenceLooks LikeValue
user2._existsexactly matchtrue
user1.getConnectionName()exactly match'second_connection'
user2.getConnectionName()exactly match'second_connection'
await FedacoTestUser.useConnection('second_connection').count()match1
typescript
user2 = await FedacoTestUser.useConnection('second_connection').firstOrCreate({
  email: 'tony.stark@gradii.com'
});
ReferenceLooks LikeValue
user2.getConnectionName()exactly match'second_connection'
await FedacoTestUser.useConnection('second_connection').count()match2

see also prerequisites

Released under the MIT License.