This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // first partially load author with `id` and `email` only | |
| const a1 = await em.findOneOrFail(Author, 123, { fields: ['id', 'email'] }); | |
| a1.email = 'lol'; // let's change the email | |
| // reloading with same fields won't fire the query (as before) | |
| const a2 = await em.findOneOrFail(Author, 123, { fields: ['email'] }); | |
| console.log(a1 === a2); // true, same entity instance, no query was fired | |
| // reloading with additional fields will work without `refresh: true` | |
| const a3 = await em.findOneOrFail(Author, 123, { fields: ['id', 'age'] }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity() | |
| class Owner { | |
| @PrimaryKey() | |
| id!: number; | |
| @Property() | |
| name!: string; | |
| @Embedded(() => [Cat, Dog]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // querying for author will trigger auto-flush if we have new author persisted | |
| const a1 = new Author(...); | |
| em.persist(a1); | |
| const r1 = await em.find(Author, {}); | |
| // querying author won't trigger auto-flush if we have new book, but no changes on author | |
| const b4 = new Book(...); | |
| em.persist(b4); | |
| const r2 = await em.find(Author, {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Here you choose the base Docker image for the actor. Apify provides the following images: | |
| # apify/actor-node-basic | |
| # apify/actor-node-chrome | |
| # apify/actor-node-puppeteer | |
| # However, you can use any other image from Docker Hub. | |
| # For more information, see https://apify.com/docs/actor#base-images | |
| FROM apify/actor-node:16 | |
| # Copy all files and directories from the directory to the Docker image | |
| COPY . ./ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (let i = 1; i <= 5; i++) { | |
| const u = new User(`Peter ${i}`, `peter+${i}@foo.bar`); | |
| em.persist(u); | |
| } | |
| await em.flush(); | |
| // insert into `user` (`name`, `email`) values | |
| // ('Peter 1', 'peter+1@foo.bar'), | |
| // ('Peter 2', 'peter+2@foo.bar'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const orm = await MikroORM.init({ | |
| entities: [Author, Book], | |
| dbName: 'my-db-name', | |
| pool: { min: 10, max: 20 }, // see https://github.com/vincit/tarn.js#usage for other pool options | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const conn = orm.em.getConnection() as AbstractSqlConnection; | |
| // you can make sure the `em` is correctly typed to `EntityManager<AbstractSqlDriver>` | |
| // or one of its implementations: | |
| // const em: EntityManager<AbstractSqlDriver> = orm.em; | |
| const knex = conn.getKnex(); | |
| // do what ever you need with `knex` | |
| const res = await knex; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const qb = orm.em.createQueryBuilder(Author); | |
| qb.update({ name: 'test 123', type: PublisherType.GLOBAL }).where({ id: 123, type: PublisherType.LOCAL }); | |
| const knex = qb.getKnexQuery(); // instance of Knex' QueryBuilder | |
| // do what ever you need with `knex` | |
| const res = await orm.em.getConnection().execute(knex); | |
| const entities = res.map(a => orm.em.map(Author, a)); | |
| console.log(entities); // Author[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| orm.em.persist(new Entity()); // no auto-flushing by default | |
| await orm.em.flush(); | |
| await orm.em.persist(new Entity(), true); // you can still use second parameter to auto-flush |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // correct query | |
| em.find(Author, { | |
| favouriteBook: { | |
| author: { name: '...' }, | |
| }, | |
| age: { $gte: 40 }, // operators are also supported | |
| }); | |
| // 2 errors will be reported here | |
| em.find(Author, { |