Git Product home page Git Product logo

nestjs-example-app's Introduction

MikroORM

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite (including libSQL) databases.

Heavily inspired by Doctrine and Hibernate.

NPM version NPM dev version Chat on discord Downloads Coverage Status Maintainability Build Status

๐Ÿค” Unit of What?

You might be asking: What the hell is Unit of Work and why should I care about it?

Unit of Work maintains a list of objects (entities) affected by a business transaction and coordinates the writing out of changes. (Martin Fowler)

Identity Map ensures that each object (entity) gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them. (Martin Fowler)

So what benefits does it bring to us?

Implicit Transactions

First and most important implication of having Unit of Work is that it allows handling transactions automatically.

When you call em.flush(), all computed changes are queried inside a database transaction (if supported by given driver). This means that you can control the boundaries of transactions simply by calling em.persistLater() and once all your changes are ready, calling flush() will run them inside a transaction.

You can also control the transaction boundaries manually via em.transactional(cb).

const user = await em.findOneOrFail(User, 1);
user.email = '[email protected]';
const car = new Car();
user.cars.add(car);

// thanks to bi-directional cascading we only need to persist user entity
// flushing will create a transaction, insert new car and update user with new email
// as user entity is managed, calling flush() is enough
await em.flush();

ChangeSet based persistence

MikroORM allows you to implement your domain/business logic directly in the entities. To maintain always valid entities, you can use constructors to mark required properties. Let's define the User entity used in previous example:

@Entity()
export class User {

  @PrimaryKey()
  id!: number;

  @Property()
  name!: string;

  @OneToOne(() => Address)
  address?: Address;

  @ManyToMany(() => Car)
  cars = new Collection<Car>(this);

  constructor(name: string) {
    this.name = name;
  }

}

Now to create new instance of the User entity, we are forced to provide the name:

const user = new User('John Doe'); // name is required to create new user instance
user.address = new Address('10 Downing Street'); // address is optional

Once your entities are loaded, make a number of synchronous actions on your entities, then call em.flush(). This will trigger computing of change sets. Only entities (and properties) that were changed will generate database queries, if there are no changes, no transaction will be started.

const user = await em.findOneOrFail(User, 1, {
  populate: ['cars', 'address.city'],
});
user.title = 'Mr.';
user.address.street = '10 Downing Street'; // address is 1:1 relation of Address entity
user.cars.getItems().forEach(car => car.forSale = true); // cars is 1:m collection of Car entities
const car = new Car('VW');
user.cars.add(car);

// now we can flush all changes done to managed entities
await em.flush();

em.flush() will then execute these queries from the example above:

begin;
update "user" set "title" = 'Mr.' where "id" = 1;
update "user_address" set "street" = '10 Downing Street' where "id" = 123;
update "car"
  set "for_sale" = case
    when ("id" = 1) then true
    when ("id" = 2) then true
    when ("id" = 3) then true
    else "for_sale" end
  where "id" in (1, 2, 3)
insert into "car" ("brand", "owner") values ('VW', 1);
commit;

Identity Map

Thanks to Identity Map, you will always have only one instance of given entity in one context. This allows for some optimizations (skipping loading of already loaded entities), as well as comparison by identity (ent1 === ent2).

๐Ÿ“– Documentation

MikroORM documentation, included in this repo in the root directory, is built with Docusaurus and publicly hosted on GitHub Pages at https://mikro-orm.io.

There is also auto-generated CHANGELOG.md file based on commit messages (via semantic-release).

โœจ Core Features

๐Ÿ“ฆ Example Integrations

You can find example integrations for some popular frameworks in the mikro-orm-examples repository:

TypeScript Examples

JavaScript Examples

๐Ÿš€ Quick Start

First install the module via yarn or npm and do not forget to install the database driver as well:

Since v4, you should install the driver package, but not the db connector itself, e.g. install @mikro-orm/sqlite, but not sqlite3 as that is already included in the driver package.

yarn add @mikro-orm/core @mikro-orm/mongodb       # for mongo
yarn add @mikro-orm/core @mikro-orm/mysql         # for mysql/mariadb
yarn add @mikro-orm/core @mikro-orm/mariadb       # for mysql/mariadb
yarn add @mikro-orm/core @mikro-orm/postgresql    # for postgresql
yarn add @mikro-orm/core @mikro-orm/mssql         # for mssql
yarn add @mikro-orm/core @mikro-orm/sqlite        # for sqlite
yarn add @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
yarn add @mikro-orm/core @mikro-orm/libsql        # for libsql

or

npm i -s @mikro-orm/core @mikro-orm/mongodb       # for mongo
npm i -s @mikro-orm/core @mikro-orm/mysql         # for mysql/mariadb
npm i -s @mikro-orm/core @mikro-orm/mariadb       # for mysql/mariadb
npm i -s @mikro-orm/core @mikro-orm/postgresql    # for postgresql
npm i -s @mikro-orm/core @mikro-orm/mssql         # for mssql
npm i -s @mikro-orm/core @mikro-orm/sqlite        # for sqlite
npm i -s @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
npm i -s @mikro-orm/core @mikro-orm/libsql        # for libsql

Next, if you want to use decorators for your entity definition, you will need to enable support for decorators as well as esModuleInterop in tsconfig.json via:

"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,

Alternatively, you can use EntitySchema.

Then call MikroORM.init as part of bootstrapping your app:

To access driver specific methods like em.createQueryBuilder() we need to specify the driver type when calling MikroORM.init(). Alternatively we can cast the orm.em to EntityManager exported from the driver package:

import { EntityManager } from '@mikro-orm/postgresql';
const em = orm.em as EntityManager;
const qb = em.createQueryBuilder(...);
import type { PostgreSqlDriver } from '@mikro-orm/postgresql'; // or any other SQL driver package

const orm = await MikroORM.init<PostgreSqlDriver>({
  entities: ['./dist/entities'], // path to your JS entities (dist), relative to `baseDir`
  dbName: 'my-db-name',
  type: 'postgresql',
});
console.log(orm.em); // access EntityManager via `em` property

There are more ways to configure your entities, take a look at installation page.

Read more about all the possible configuration options in Advanced Configuration section.

Then you will need to fork entity manager for each request so their identity maps will not collide. To do so, use the RequestContext helper:

const app = express();

app.use((req, res, next) => {
  RequestContext.create(orm.em, next);
});

You should register this middleware as the last one just before request handlers and before any of your custom middleware that is using the ORM. There might be issues when you register it before request processing middleware like queryParser or bodyParser, so definitely register the context after them.

More info about RequestContext is described here.

Now you can start defining your entities (in one of the entities folders). This is how simple entity can look like in mongo driver:

./entities/MongoBook.ts

@Entity()
export class MongoBook {

  @PrimaryKey()
  _id: ObjectID;

  @SerializedPrimaryKey()
  id: string;

  @Property()
  title: string;

  @ManyToOne(() => Author)
  author: Author;

  @ManyToMany(() => BookTag)
  tags = new Collection<BookTag>(this);

  constructor(title: string, author: Author) {
    this.title = title;
    this.author = author;
  }

}

For SQL drivers, you can use id: number PK:

./entities/SqlBook.ts

@Entity()
export class SqlBook {

  @PrimaryKey()
  id: number;

}

Or if you want to use UUID primary keys:

./entities/UuidBook.ts

import { v4 } from 'uuid';

@Entity()
export class UuidBook {

  @PrimaryKey()
  uuid = v4();

}

More information can be found in defining entities section in docs.

When you have your entities defined, you can start using ORM either via EntityManager or via EntityRepositorys.

To save entity state to database, you need to persist it. Persist takes care or deciding whether to use insert or update and computes appropriate change-set. Entity references that are not persisted yet (does not have identifier) will be cascade persisted automatically.

// use constructors in your entities for required parameters
const author = new Author('Jon Snow', '[email protected]');
author.born = new Date();

const publisher = new Publisher('7K publisher');

const book1 = new Book('My Life on The Wall, part 1', author);
book1.publisher = publisher;
const book2 = new Book('My Life on The Wall, part 2', author);
book2.publisher = publisher;
const book3 = new Book('My Life on The Wall, part 3', author);
book3.publisher = publisher;

// just persist books, author and publisher will be automatically cascade persisted
await em.persistAndFlush([book1, book2, book3]);

To fetch entities from database you can use find() and findOne() of EntityManager:

const authors = em.find(Author, {}, { populate: ['books'] });

for (const author of authors) {
  console.log(author); // instance of Author entity
  console.log(author.name); // Jon Snow

  for (const book of author.books) { // iterating books collection
    console.log(book); // instance of Book entity
    console.log(book.title); // My Life on The Wall, part 1/2/3
  }
}

More convenient way of fetching entities from database is by using EntityRepository, that carries the entity name, so you do not have to pass it to every find and findOne calls:

const booksRepository = em.getRepository(Book);

const books = await booksRepository.find({ author: '...' }, { 
  populate: ['author'],
  limit: 1,
  offset: 2,
  orderBy: { title: QueryOrder.DESC },
});

console.log(books); // Loaded<Book, 'author'>[]

Take a look at docs about working with EntityManager or using EntityRepository instead.

๐Ÿค Contributing

Contributions, issues and feature requests are welcome. Please read CONTRIBUTING.md for details on the process for submitting pull requests to us.

Authors

๐Ÿ‘ค Martin Adรกmek

See also the list of contributors who participated in this project.

Show Your Support

Please โญ๏ธ this repository if this project helped you!

๐Ÿ“ License

Copyright ยฉ 2018 Martin Adรกmek.

This project is licensed under the MIT License - see the LICENSE file for details.

nestjs-example-app's People

Contributors

b4nan avatar dependabot[bot] avatar erie0210 avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nestjs-example-app's Issues

Not work update

Update not work

curl -XPUT -d '{ "id":"1", "title": "book title 1x3", "author": { "id": "1", "name": "author name 1x3", "email":"[email protected]", "termsAccepted": "true" } }' -H "Content-Type: application/json" http://127.0.0.1:3000/book/1

Log output

select `b0`.* from `book` as `b0` where `b0`.`id` = 1 limit 1 [took 3 ms]

Also is need to change @Param() to @Param('id')

Also I changed const book = await this.bookRepository.findOne(+id); with const book = await this.bookRepository.findOne({ id: +id });

And add

@Entity()
export class Book extends BaseEntity {
  [PrimaryKeyType]?: [number];

  @PrimaryKey()
  id!: number;

Update to NestJS 8.0 / Errors

Hi,

I quickly tried upgrading my NestJS packages to v8 (coming from v7) and was finding an error that said

EntityManager was not imported / is not available in the UserModule (showing the Service that uses the em below).

There is likely something wrong with importing the EntityManager and injecting it.

Could you bump this project up to use the newest versions of NestJS and resolve any issues that might appear?

Thanks!

@Injectable()
export class UserService {
  constructor(
    @Inject(forwardRef(() => UserService))
    private readonly userService: UserService,
    private em: EntityManager<PostgreSqlDriver>,
  ) {}
}

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • Update dependency @types/express to v4.17.13
  • Update dependency @types/supertest to v2.0.11
  • Update dependency nodemon to v2.0.15
  • Update dependency rxjs to v6.6.7
  • Update dependency typescript to v3.9.10
  • Update dependency webpack-node-externals to v2.5.2
  • Update dependency @mikro-orm/nestjs to v4.3.1
  • Update dependency @types/node to v14.18.12
  • Update dependency prettier to v2.5.1
  • Update dependency ts-jest to v26.5.6
  • Update dependency ts-loader to v8.3.0
  • Update dependency tsconfig-paths to v3.12.0
  • Update dependency webpack to v4.46.0
  • Update mikro-orm monorepo to v4.5.10 (@mikro-orm/cli, @mikro-orm/core, @mikro-orm/mysql, @mikro-orm/reflection)
  • Update nest monorepo to v7.6.18 (@nestjs/common, @nestjs/core, @nestjs/platform-express, @nestjs/testing)
  • Update dependency @types/node to v16
  • Update dependency mysql to v8
  • Update dependency rxjs to v7
  • Update dependency supertest to v6
  • Update dependency ts-loader to v9
  • Update dependency ts-node to v10
  • Update dependency typescript to v4
  • Update dependency webpack to v5
  • Update dependency webpack-cli to v4
  • Update dependency webpack-node-externals to v3
  • Update jest monorepo (major) (@types/jest, jest, ts-jest)
  • Update mikro-orm monorepo to v5 (major) (@mikro-orm/cli, @mikro-orm/core, @mikro-orm/mysql, @mikro-orm/reflection)
  • Update nest monorepo to v8 (major) (@nestjs/common, @nestjs/core, @nestjs/platform-express, @nestjs/testing)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • Pin dependencies (@mikro-orm/cli, @mikro-orm/core, @mikro-orm/mysql, @mikro-orm/nestjs, @mikro-orm/reflection, @mikro-orm/sql-highlighter, @nestjs/common, @nestjs/core, @nestjs/platform-express, @nestjs/testing, @types/express, @types/node, @types/supertest, jest, nodemon, prettier, reflect-metadata, rimraf, rxjs, supertest, ts-jest, ts-loader, ts-node, tsconfig-paths, typescript, webpack, webpack-cli, webpack-node-externals)
  • Pin dependencies (@types/jest, jest)

  • Check this box to trigger a request for Renovate to run again on this repository

MikroORM failed to connect to database mikro-orm-nest-ts on mysql://[email protected]:3307

I cloned the repo then ran:

yarn install`
docker-compose up -d`
yarn start:dev`

Outputs:

[+] Running 1/0
 โ ฟ Container mysql  Recreated                                                                                           0.1s
Attaching to mysql
mysql  | 2021-11-26 10:18:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
mysql  | 2021-11-26 10:18:03+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql  | 2021-11-26 10:18:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
mysql  | 2021-11-26 10:18:03+00:00 [Note] [Entrypoint]: Initializing database files
mysql  | 2021-11-26T10:18:03.512913Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql  | 2021-11-26T10:18:03.702512Z 0 [Warning] InnoDB: New log files created, LSN=45790
mysql  | 2021-11-26T10:18:03.742351Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
mysql  | 2021-11-26T10:18:03.755362Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 24040116-4ea2-11ec-a56e-0242ac130402.
mysql  | 2021-11-26T10:18:03.758786Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
mysql  | 2021-11-26T10:18:04.226619Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
mysql  | 2021-11-26T10:18:04.226639Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
mysql  | 2021-11-26T10:18:04.226960Z 0 [Warning] CA certificate ca.pem is self signed.
mysql  | 2021-11-26T10:18:04.437062Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysql  | 2021-11-26 10:18:07+00:00 [Note] [Entrypoint]: Database files initialized
mysql  | 2021-11-26 10:18:07+00:00 [Note] [Entrypoint]: Starting temporary server
mysql  | 2021-11-26 10:18:07+00:00 [Note] [Entrypoint]: Waiting for server startup
mysql  | 2021-11-26T10:18:07.840998Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql  | 2021-11-26T10:18:07.841876Z 0 [Note] mysqld (mysqld 5.7.36) starting as process 77 ...
mysql  | 2021-11-26T10:18:07.844114Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql  | 2021-11-26T10:18:07.844148Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql  | 2021-11-26T10:18:07.844150Z 0 [Note] InnoDB: Uses event mutexes
mysql  | 2021-11-26T10:18:07.844153Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql  | 2021-11-26T10:18:07.844156Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysql  | 2021-11-26T10:18:07.844159Z 0 [Note] InnoDB: Using Linux native AIO
mysql  | 2021-11-26T10:18:07.844332Z 0 [Note] InnoDB: Number of pools: 1
mysql  | 2021-11-26T10:18:07.844525Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql  | 2021-11-26T10:18:07.845801Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql  | 2021-11-26T10:18:07.850237Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql  | 2021-11-26T10:18:07.851616Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql  | 2021-11-26T10:18:07.871218Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysql  | 2021-11-26T10:18:07.881870Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql  | 2021-11-26T10:18:07.881937Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql  | 2021-11-26T10:18:07.899654Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql  | 2021-11-26T10:18:07.900533Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql  | 2021-11-26T10:18:07.900552Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql  | 2021-11-26T10:18:07.901044Z 0 [Note] InnoDB: Waiting for purge to start
mysql  | 2021-11-26T10:18:07.951244Z 0 [Note] InnoDB: 5.7.36 started; log sequence number 2749723
mysql  | 2021-11-26T10:18:07.951465Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql  | 2021-11-26T10:18:07.951803Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql  | 2021-11-26T10:18:07.953204Z 0 [Note] InnoDB: Buffer pool(s) load completed at 211126 10:18:07
mysql  | 2021-11-26T10:18:07.959073Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysql  | 2021-11-26T10:18:07.959111Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
mysql  | 2021-11-26T10:18:07.959119Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
mysql  | 2021-11-26T10:18:07.959124Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
mysql  | 2021-11-26T10:18:07.960222Z 0 [Warning] CA certificate ca.pem is self signed.
mysql  | 2021-11-26T10:18:07.960303Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
mysql  | 2021-11-26T10:18:07.965992Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql  | 2021-11-26T10:18:07.977949Z 0 [Note] Event Scheduler: Loaded 0 events
mysql  | 2021-11-26T10:18:07.978424Z 0 [Note] mysqld: ready for connections.
mysql  | Version: '5.7.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
mysql  | 2021-11-26 10:18:08+00:00 [Note] [Entrypoint]: Temporary server started.
mysql  | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql  | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mysql  | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql  | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
mysql  | 
mysql  | 2021-11-26 10:18:10+00:00 [Note] [Entrypoint]: Stopping temporary server
mysql  | 2021-11-26T10:18:10.392735Z 0 [Note] Giving 0 client threads a chance to die gracefully
mysql  | 2021-11-26T10:18:10.392848Z 0 [Note] Shutting down slave threads
mysql  | 2021-11-26T10:18:10.392861Z 0 [Note] Forcefully disconnecting 0 remaining clients
mysql  | 2021-11-26T10:18:10.392870Z 0 [Note] Event Scheduler: Purging the queue. 0 events
mysql  | 2021-11-26T10:18:10.392971Z 0 [Note] Binlog end
mysql  | 2021-11-26T10:18:10.393581Z 0 [Note] Shutting down plugin 'ngram'
mysql  | 2021-11-26T10:18:10.393600Z 0 [Note] Shutting down plugin 'partition'
mysql  | 2021-11-26T10:18:10.393603Z 0 [Note] Shutting down plugin 'BLACKHOLE'
mysql  | 2021-11-26T10:18:10.393609Z 0 [Note] Shutting down plugin 'ARCHIVE'
mysql  | 2021-11-26T10:18:10.393613Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
mysql  | 2021-11-26T10:18:10.393648Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
mysql  | 2021-11-26T10:18:10.393655Z 0 [Note] Shutting down plugin 'MyISAM'
mysql  | 2021-11-26T10:18:10.393665Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
mysql  | 2021-11-26T10:18:10.393670Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
mysql  | 2021-11-26T10:18:10.393673Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
mysql  | 2021-11-26T10:18:10.393676Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
mysql  | 2021-11-26T10:18:10.393680Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
mysql  | 2021-11-26T10:18:10.393683Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
mysql  | 2021-11-26T10:18:10.393686Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
mysql  | 2021-11-26T10:18:10.393690Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
mysql  | 2021-11-26T10:18:10.393693Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
mysql  | 2021-11-26T10:18:10.393696Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
mysql  | 2021-11-26T10:18:10.393699Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
mysql  | 2021-11-26T10:18:10.393703Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
mysql  | 2021-11-26T10:18:10.393708Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
mysql  | 2021-11-26T10:18:10.393713Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
mysql  | 2021-11-26T10:18:10.393718Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
mysql  | 2021-11-26T10:18:10.393723Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
mysql  | 2021-11-26T10:18:10.393726Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
mysql  | 2021-11-26T10:18:10.393733Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
mysql  | 2021-11-26T10:18:10.393736Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
mysql  | 2021-11-26T10:18:10.393740Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
mysql  | 2021-11-26T10:18:10.393743Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
mysql  | 2021-11-26T10:18:10.393746Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
mysql  | 2021-11-26T10:18:10.393749Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
mysql  | 2021-11-26T10:18:10.393752Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
mysql  | 2021-11-26T10:18:10.393754Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
mysql  | 2021-11-26T10:18:10.393758Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
mysql  | 2021-11-26T10:18:10.393761Z 0 [Note] Shutting down plugin 'INNODB_CMP'
mysql  | 2021-11-26T10:18:10.393764Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
mysql  | 2021-11-26T10:18:10.393768Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
mysql  | 2021-11-26T10:18:10.393771Z 0 [Note] Shutting down plugin 'INNODB_TRX'
mysql  | 2021-11-26T10:18:10.393775Z 0 [Note] Shutting down plugin 'InnoDB'
mysql  | 2021-11-26T10:18:10.393846Z 0 [Note] InnoDB: FTS optimize thread exiting.
mysql  | 2021-11-26T10:18:10.393983Z 0 [Note] InnoDB: Starting shutdown...
mysql  | 2021-11-26T10:18:10.494304Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
mysql  | 2021-11-26T10:18:10.494706Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 211126 10:18:10
mysql  | 2021-11-26T10:18:11.919319Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12659811
mysql  | 2021-11-26T10:18:11.922397Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
mysql  | 2021-11-26T10:18:11.922428Z 0 [Note] Shutting down plugin 'MEMORY'
mysql  | 2021-11-26T10:18:11.922436Z 0 [Note] Shutting down plugin 'CSV'
mysql  | 2021-11-26T10:18:11.922443Z 0 [Note] Shutting down plugin 'sha256_password'
mysql  | 2021-11-26T10:18:11.922448Z 0 [Note] Shutting down plugin 'mysql_native_password'
mysql  | 2021-11-26T10:18:11.922630Z 0 [Note] Shutting down plugin 'binlog'
mysql  | 2021-11-26T10:18:11.925154Z 0 [Note] mysqld: Shutdown complete
mysql  | 
mysql  | 2021-11-26 10:18:12+00:00 [Note] [Entrypoint]: Temporary server stopped
mysql  | 
mysql  | 2021-11-26 10:18:12+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
mysql  | 
mysql  | 2021-11-26T10:18:12.572287Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql  | 2021-11-26T10:18:12.573006Z 0 [Note] mysqld (mysqld 5.7.36) starting as process 1 ...
mysql  | 2021-11-26T10:18:12.574858Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql  | 2021-11-26T10:18:12.574876Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql  | 2021-11-26T10:18:12.574879Z 0 [Note] InnoDB: Uses event mutexes
mysql  | 2021-11-26T10:18:12.574881Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql  | 2021-11-26T10:18:12.574884Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysql  | 2021-11-26T10:18:12.574886Z 0 [Note] InnoDB: Using Linux native AIO
mysql  | 2021-11-26T10:18:12.575012Z 0 [Note] InnoDB: Number of pools: 1
mysql  | 2021-11-26T10:18:12.575059Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql  | 2021-11-26T10:18:12.576082Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql  | 2021-11-26T10:18:12.580143Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql  | 2021-11-26T10:18:12.581585Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql  | 2021-11-26T10:18:12.592908Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysql  | 2021-11-26T10:18:12.608268Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql  | 2021-11-26T10:18:12.608339Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql  | 2021-11-26T10:18:12.626275Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql  | 2021-11-26T10:18:12.627176Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql  | 2021-11-26T10:18:12.627189Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql  | 2021-11-26T10:18:12.627596Z 0 [Note] InnoDB: Waiting for purge to start
mysql  | 2021-11-26T10:18:12.677919Z 0 [Note] InnoDB: 5.7.36 started; log sequence number 12659811
mysql  | 2021-11-26T10:18:12.678448Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql  | 2021-11-26T10:18:12.678812Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql  | 2021-11-26T10:18:12.681187Z 0 [Note] InnoDB: Buffer pool(s) load completed at 211126 10:18:12
mysql  | 2021-11-26T10:18:12.684562Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysql  | 2021-11-26T10:18:12.684591Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
mysql  | 2021-11-26T10:18:12.684597Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
mysql  | 2021-11-26T10:18:12.684601Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
mysql  | 2021-11-26T10:18:12.685390Z 0 [Warning] CA certificate ca.pem is self signed.
mysql  | 2021-11-26T10:18:12.685446Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
mysql  | 2021-11-26T10:18:12.686171Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysql  | 2021-11-26T10:18:12.686236Z 0 [Note] IPv6 is available.
mysql  | 2021-11-26T10:18:12.686253Z 0 [Note]   - '::' resolves to '::';
mysql  | 2021-11-26T10:18:12.686274Z 0 [Note] Server socket created on IP: '::'.
mysql  | 2021-11-26T10:18:12.690894Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql  | 2021-11-26T10:18:12.702727Z 0 [Note] Event Scheduler: Loaded 0 events
mysql  | 2021-11-26T10:18:12.703337Z 0 [Note] mysqld: ready for connections.
mysql  | Version: '5.7.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
mysql  | 2021-11-26T10:19:11.736873Z 2 [Note] Unknown database 'mikro-orm-nest-ts'

--

yarn run v1.22.17
$ nodemon
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src/**/*
[nodemon] watching extensions: ts
[nodemon] starting `ts-node -r tsconfig-paths/register src/main.ts`
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [NestFactory] Starting Nest application...
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] OrmModule dependencies initialized +19ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] MikroOrmModule dependencies initialized +0ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] ORM entity discovery started, using ReflectMetadataProvider
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] - processing entity Author
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] - processing entity Book
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] - processing entity BookTag
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] - processing entity Publisher
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] - processing entity BaseEntity
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [discovery] - entity discovery finished, found 6 entities, took 20 ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [MikroORM] [info] MikroORM failed to connect to database mikro-orm-nest-ts on mysql://[email protected]:3307
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] MikroOrmCoreModule dependencies initialized +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] MikroOrmModule dependencies initialized +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] AuthorModule dependencies initialized +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [InstanceLoader] BookModule dependencies initialized +0ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RoutesResolver] AppController {}: +6ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {, GET} route +2ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RoutesResolver] AuthorController {/author}: +0ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/author, GET} route +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/author/:id, GET} route +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/author, POST} route +0ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/author/:id, PUT} route +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RoutesResolver] BookController {/book}: +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/book, GET} route +0ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/book/:id, GET} route +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/book, POST} route +1ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [RouterExplorer] Mapped {/book/:id, PUT} route +0ms
[Nest] 360637   - 11/26/2021, 11:19:11 AM   [NestApplication] Nest application successfully started +3ms

To my understanding the orm should successfully connect to the database.

Hope this can be resolved, best Fred.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.