Function NewQuery
basic create model
const model = await new FedacoTestUser().NewQuery().create({
id: 1,
email: 'linbolen@gradii.com'
});
Reference Looks Like Value model.emailexactly match 'linbolen@gradii.com'
see also prerequisites
basic model collection retrieval
await FedacoTestUser.createQuery().create({
id: 1,
email: 'linbolen@gradii.com'
});
await FedacoTestUser.createQuery().create({
id: 2,
email: 'xsilen@gradii.com'
});
const models = await new FedacoTestUser().NewQuery().oldest('id').get();
Reference Looks Like Value isArray(models)exactly match truemodels[0]instance type exactly match FedacoTestUsermodels[1]instance type exactly match FedacoTestUsermodels[0].emailexactly match 'linbolen@gradii.com'models[1].emailexactly match 'xsilen@gradii.com'
see also prerequisites
basic model retrieval
const factory = new FedacoTestUser();
await factory.NewQuery().create({
id: 1,
email: 'linbolen@gradii.com'
});
await factory.NewQuery().create({
id: 2,
email: 'xsilen@gradii.com'
});
Reference Looks Like Value await factory.NewQuery().where('email', 'linbolen@gradii.com').doesntExist()exactly match falseawait factory.NewQuery().where('email', 'mohamed@laravel.com').doesntExist()exactly match true
Reference Looks Like Value model.emailexactly match 'linbolen@gradii.com'model.email !== undefinedexactly match true
Reference Looks Like Value friends !== undefinedexactly match truefriendsmatch []
Reference Looks Like Value modelinstance type exactly match FedacoTestUsermodel.idmatch 1
Reference Looks Like Value modelinstance type exactly match FedacoTestUsermodel.idmatch 2
Reference Looks Like Value missingexactly match Undefined();
Reference Looks Like Value isArray(collection)exactly match truecollection.lengthexactly match 0
Reference Looks Like Value isArray(collection)exactly match truecollection.lengthexactly match 2
// .cursor();
for (const m of models) {
expect(m.id).toEqual(1);
expect(m.getConnectionName()).toBe('default');
}see also prerequisites
fresh method on model
const now = new Date();
const nowSerialized = formatISO(startOfSecond(now));
const nowWithFractionsSerialized = now.toJSON();
// Carbon.setTestNow(now);
const storedUser1 = await FedacoTestUser.createQuery().create({
id: 1,
email: 'linbolen@gradii.com',
birthday: now
});
await storedUser1.NewQuery().update({
email: 'dev@mathieutu.ovh',
name: 'Mathieu TUDISCO'
});
const freshStoredUser1 = await storedUser1.Fresh();
const storedUser2 = await FedacoTestUser.createQuery().create({
id: 2,
email: 'linbolen@gradii.com',
birthday: now
});
await storedUser2.NewQuery().update({
email: 'dev@mathieutu.ovh'
});
const freshStoredUser2 = await storedUser2.Fresh();
const notStoredUser = FedacoTestUser.initAttributes({
id: 3,
email: 'linbolen@gradii.com',
birthday: now
});
const freshNotStoredUser = await notStoredUser.Fresh();
Reference Looks Like Value freshStoredUser1.toArray()match `({
'id' : 1,
'name' : 'Mathieu TUDISCO',
'email' : 'dev@mathieutu.ovh',
'birthday' : nowWithFractionsSerialized,
'created_at': nowSerialized,
'updated_at': nowSerialized
});` |
|
storedUser1| instance type exactly match |FedacoTestUser| |storedUser2.toArray()| match |({ 'id' : 2, 'email' : 'linbolen@gradii.com', 'birthday' : nowWithFractionsSerialized, 'created_at': nowSerialized, 'updated_at': nowSerialized });| |freshStoredUser2.toArray()| match |({ 'id' : 2, 'name' : null, 'email' : 'dev@mathieutu.ovh', 'birthday' : nowWithFractionsSerialized, 'created_at': nowSerialized, 'updated_at': nowSerialized });| |storedUser2| instance type exactly match |FedacoTestUser| |notStoredUser.toArray()| match |({ 'id' : 3, 'email' : 'linbolen@gradii.com', 'birthday': nowWithFractionsSerialized });| |freshNotStoredUser| exactly match |null|
see also prerequisites
paginated model collection retrieval when no elements and default per page
const models = await new FedacoTestUser().NewQuery().oldest('id').paginate();see also prerequisites
paginated model collection retrieval when no elements
// Paginator.currentPageResolver(() => {
// return 1;
// });
let models = await new FedacoTestUser().NewQuery().oldest('id').paginate(1, 2);// expect(models).toInstanceOf(LengthAwarePaginator);
// Paginator.currentPageResolver(() => {
// return 2;
// });
models = await new FedacoTestUser().NewQuery().oldest('id').paginate(2, 2);see also prerequisites
paginated model collection retrieval
await new FedacoTestUser().NewQuery().create({
id: 1,
email: 'linbolen@gradii.com'
});
await new FedacoTestUser().NewQuery().create({
id: 2,
email: 'xsilen@gradii.com'
});
await new FedacoTestUser().NewQuery().create({
id: 3,
email: 'foo@gmail.com'
});
// Paginator.currentPageResolver(() => {
// return 1;
// });
let models = await new FedacoTestUser().NewQuery().oldest('id').paginate(1, 2);
Reference Looks Like Value models.items[0]instance type exactly match FedacoTestUsermodels.items[1]instance type exactly match FedacoTestUsermodels.items[0].emailexactly match 'linbolen@gradii.com'models.items[1].emailexactly match 'xsilen@gradii.com'
Reference Looks Like Value models.items.lengthexactly match 1models.items[0]instance type exactly match FedacoTestUsermodels.items[0].emailexactly match 'foo@gmail.com'
see also prerequisites