Skip to content

Instantly share code, notes, and snippets.

@B4nan
Last active February 6, 2022 02:33
Show Gist options
  • Save B4nan/9c9bd15a84df4650e9e5e26cd6fd56cd to your computer and use it in GitHub Desktop.
Save B4nan/9c9bd15a84df4650e9e5e26cd6fd56cd to your computer and use it in GitHub Desktop.
const res1 = await em.createQueryBuilder(Publisher).insert({
name: 'p1',
type: PublisherType.GLOBAL,
});
// res1 is of type `QueryResult<Publisher>`
console.log(res1.insertId);
const res2 = await em.createQueryBuilder(Publisher)
.select('*')
.where({ name: 'p1' })
.limit(5);
// res2 is Publisher[]
console.log(res2.map(p => p.name));
const res3 = await em.createQueryBuilder(Publisher).count().where({ name: 'p1' });
// res3 is number
console.log(res3 > 0);
const res4 = await em.createQueryBuilder(Publisher)
.update({ type: PublisherType.LOCAL })
.where({ name: 'p1' });
// res4 is QueryResult<Publisher>
console.log(res4.affectedRows > 0);
const res5 = await em.createQueryBuilder(Publisher).delete().where({ name: 'p1' });
// res4 is QueryResult<Publisher>
console.log(res4.affectedRows > 0);
expect(res5.affectedRows > 0).toBe(true); // test the type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment