Skip to content

Commit

Permalink
Merge 14b88a3 into b80de4b
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Sep 23, 2019
2 parents b80de4b + 14b88a3 commit 8d300e6
Show file tree
Hide file tree
Showing 179 changed files with 8,252 additions and 3,841 deletions.
5 changes: 4 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ checks:
return-statements:
config:
threshold: 5
method-complexity:
config:
threshold: 6

engines:
duplication:
Expand All @@ -21,4 +24,4 @@ engines:
languages:
typescript:
# make it higher so it does not report bullshit like similarity of abstract method and its implementation
mass_threshold: 55
mass_threshold: 70
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/dist
/coverage
/temp
/tests/generated-entities
/.idea
/yarn-error.log
/.coveralls.yml
Expand Down
48 changes: 30 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,66 @@ MikroORM's documentation, included in this repo in the root directory, is built
There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit messages
(via `semantic-release`).

## ✨ Core features
## ✨ Core Features

- [Clean and simple entity definition](https://mikro-orm.io/defining-entities/)
- [Clean and Simple Entity Definition](https://mikro-orm.io/defining-entities/)
- [Identity Map](https://mikro-orm.io/identity-map/)
- [Entity references](https://mikro-orm.io/entity-references/)
- [Using entity constructors](https://mikro-orm.io/using-entity-constructors/)
- [Entity References](https://mikro-orm.io/entity-references/)
- [Using Entity Constructors](https://mikro-orm.io/using-entity-constructors/)
- [Collections](https://mikro-orm.io/collections/)
- [Unit of Work](https://mikro-orm.io/unit-of-work/)
- [Transactions](https://mikro-orm.io/transactions/)
- [Cascading persist and remove](https://mikro-orm.io/cascading/)
- [Using `QueryBuilder`](https://mikro-orm.io/query-builder/)
- [Preloading deeply nested structures via populate](https://mikro-orm.io/nested-populate/)
- [Property validation](https://mikro-orm.io/property-validation/)
- [Lifecycle hooks](https://mikro-orm.io/lifecycle-hooks/)
- [Vanilla JS support](https://mikro-orm.io/usage-with-js/)
- [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/nested-populate/)
- [Property Validation](https://mikro-orm.io/property-validation/)
- [Lifecycle Hooks](https://mikro-orm.io/lifecycle-hooks/)
- [Vanilla JS Support](https://mikro-orm.io/usage-with-js/)
- [Schema Generator](https://mikro-orm.io/schema-generator/)
- [Entity Generator](https://mikro-orm.io/entity-generator/)

## 📦 Example integrations
## 📦 Example Integrations

You can find example integrations for some popular frameworks in the [`mikro-orm-examples` repository](https://github.com/mikro-orm/mikro-orm-examples):

### TypeScript examples
### TypeScript Examples

- [Express + MongoDB](https://github.com/mikro-orm/mikro-orm-examples/tree/master/express-ts)
- [Nest + MySQL](https://github.com/mikro-orm/mikro-orm-examples/tree/master/nest)
- [`nestjs-mikro-orm` module](https://github.com/dario1985/nestjs-mikro-orm)

### JavaScript examples
### JavaScript Examples
- [Express + MongoDB](https://github.com/mikro-orm/mikro-orm-examples/tree/master/express-js)

## 🚀 Quick start
## Articles

- Introducing MikroORM, TypeScript data-mapper ORM with Identity Map
- on [medium.com](https://medium.com/dailyjs/introducing-mikro-orm-typescript-data-mapper-orm-with-identity-map-9ba58d049e02)
- on [dev.to](https://dev.to/b4nan/introducing-mikroorm-typescript-data-mapper-orm-with-identity-map-pc8)
- Handling transactions and concurrency in MikroORM
- on [medium.com](https://medium.com/dailyjs/handling-transactions-and-concurrency-in-mikro-orm-ba80d0a65805)
- on [dev.to](https://dev.to/b4nan/handling-transactions-and-concurrency-in-mikroorm-2cfj)

## 🚀 Quick Start

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

```
$ yarn add mikro-orm mongodb # for mongo
$ yarn add mikro-orm mysql2 # for mysql
$ yarn add mikro-orm mysql2 # for mysql/mariadb
$ yarn add mikro-orm mariadb # for mysql/mariadb
$ yarn add mikro-orm pg # for postgresql
$ yarn add mikro-orm sqlite # for sqlite
$ yarn add mikro-orm sqlite3 # for sqlite
```

or

```
$ npm i -s mikro-orm mongodb # for mongo
$ npm i -s mikro-orm mysql2 # for mysql
$ npm i -s mikro-orm mysql2 # for mysql/mariadb
$ npm i -s mikro-orm mariadb # for mysql/mariadb
$ npm i -s mikro-orm pg # for postgresql
$ npm i -s mikro-orm sqlite # for sqlite
$ npm i -s mikro-orm sqlite3 # for sqlite
```

Next you will need to enable support for [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
Expand All @@ -86,7 +99,6 @@ const orm = await MikroORM.init({
entitiesDirs: ['./dist/entities'], // path to your JS entities (dist), relative to `baseDir`
dbName: 'my-db-name',
clientUrl: '...', // defaults to 'mongodb://localhost:27017' for mongodb driver
autoFlush: false, // read more here: https://mikro-orm.io/unit-of-work/
});
console.log(orm.em); // access EntityManager via `em` property
```
Expand Down Expand Up @@ -225,7 +237,7 @@ for details on the process for submitting pull requests to us.

See also the list of contributors who [participated](https://github.com/mikro-orm/mikro-orm/contributors) in this project.

## Show your support
## Show Your Support

Please ⭐️ this repository if this project helped you!

Expand Down
7 changes: 3 additions & 4 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ discuss specifics.

- Association scopes
- Value transformers (e.g. mapping of `Date` object to formatted string)
- Support for connection pooling in MySQL and PostgresQL
- Computing schema difference based on current database state
- Schema sync (allow automatic synchronization during development)
- Allow generating entities from existing database schema
- Migrations via `umzug`
- Improved support for data types like date, time, enum, timestamp
- Support for RegExp search in SQL drivers
- Collection expressions - support querying parts of collection
- Collection pagination
- Eager loading of associations (allow having some relationship always fetched)
- Composite primary keys
- Map collections
- Single table inheritance #33
- Embedded entities (allow in-lining child entity into parent one with prefixed keys)
- Slow query log
- Optional query params logging
35 changes: 19 additions & 16 deletions docs/_includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,49 @@
<h3>Overview</h3>
<ul>
<li><a href="{{ site.github.url | default: site.url }}/installation/">Installation &amp; Usage</a></li>
<li><a href="{{ site.github.url | default: site.url }}/defining-entities/">Defining entities</a></li>
<li><a href="{{ site.github.url | default: site.url }}/defining-entities/">Defining Entities</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-manager/">EntityManager</a></li>
<li><a href="{{ site.github.url | default: site.url }}/repositories/">EntityRepository</a></li>
</ul>
<h3>Fundamentals</h3>
<ul>
<li><a href="{{ site.github.url | default: site.url }}/identity-map/">Identity Map and Request Context</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-references/">Entity references</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-constructors/">Using entity constructors</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-references/">Entity References and Reference&lt;T&gt; Wrapper</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-constructors/">Using Entity Constructors</a></li>
<li><a href="{{ site.github.url | default: site.url }}/collections/">Collections</a></li>
<li><a href="{{ site.github.url | default: site.url }}/unit-of-work/">Unit of Work</a></li>
<li><a href="{{ site.github.url | default: site.url }}/transactions/">Transactions</a></li>
<li><a href="{{ site.github.url | default: site.url }}/cascading/">Cascading persist and remove</a></li>
</ul>
<h3>Advanced features</h3>
<h3>Advanced Features</h3>
<ul>
<li><a href="{{ site.github.url | default: site.url }}/nested-populate/">Smart nested populate</a></li>
<li><a href="{{ site.github.url | default: site.url }}/query-conditions/">Smart query conditions</a></li>
<li><a href="{{ site.github.url | default: site.url }}/nested-populate/">Smart Nested Populate</a></li>
<li><a href="{{ site.github.url | default: site.url }}/query-conditions/">Smart Query Conditions</a></li>
<li><a href="{{ site.github.url | default: site.url }}/query-builder/">Using QueryBuilder</a></li>
<li><a href="{{ site.github.url | default: site.url }}/serializing/">Serializing</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-helper/">Updating entity values</a></li>
<li><a href="{{ site.github.url | default: site.url }}/property-validation/">Property validation</a></li>
<li><a href="{{ site.github.url | default: site.url }}/lifecycle-hooks/">Lifecycle hooks</a></li>
<li><a href="{{ site.github.url | default: site.url }}/naming-strategy/">Naming strategy</a></li>
<li><a href="{{ site.github.url | default: site.url }}/metadata-cache/">Metadata cache</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-helper/">Updating Entity Values</a></li>
<li><a href="{{ site.github.url | default: site.url }}/property-validation/">Property Validation</a></li>
<li><a href="{{ site.github.url | default: site.url }}/lifecycle-hooks/">Lifecycle Hooks</a></li>
<li><a href="{{ site.github.url | default: site.url }}/naming-strategy/">Naming Strategy</a></li>
<li><a href="{{ site.github.url | default: site.url }}/metadata-cache/">Metadata Cache</a></li>
<li><a href="{{ site.github.url | default: site.url }}/debugging/">Debugging</a></li>
<li><a href="{{ site.github.url | default: site.url }}/schema-generator/">Schema generator</a></li>
<li><a href="{{ site.github.url | default: site.url }}/schema-generator/">Schema Generator</a></li>
<li><a href="{{ site.github.url | default: site.url }}/entity-generator/">Entity Generator</a></li>
<li><a href="{{ site.github.url | default: site.url }}/read-connections/">Read Replica Connections</a></li>
</ul>
<h3>Usage with different drivers</h3>
<h3>Usage with Different Drivers</h3>
<ul>
<li><a href="{{ site.github.url | default: site.url }}/usage-with-sql/">Usage with Postgres, MySQL and SQLite</a></li>
<li><a href="{{ site.github.url | default: site.url }}/usage-with-sql/">Usage with SQL Drivers</a></li>
<li><a href="{{ site.github.url | default: site.url }}/usage-with-mongo/">Usage with MongoDB</a></li>
</ul>
<h3>Recipes</h3>
<ul>
<li><a href="{{ site.github.url | default: site.url }}/usage-with-nestjs/">Usage with NestJS</a></li>
<li><a href="{{ site.github.url | default: site.url }}/usage-with-js/">Usage with Vanilla JS</a></li>
<li><a href="{{ site.github.url | default: site.url }}/custom-driver/">Creating custom driver</a></li>
<li><a href="{{ site.github.url | default: site.url }}/custom-driver/">Creating Custom Driver</a></li>
<li><a href="{{ site.github.url | default: site.url }}/multiple-schemas/">Using Multiple Schemas</a></li>
</ul>
<h3>Example integrations</h3>
<h3>Example Integrations</h3>
<ul>
<li><a href="https://github.com/mikro-orm/mikro-orm-examples/tree/master/express-ts">Express + MongoDB + TypeScript</a></li>
<li><a href="https://github.com/mikro-orm/mikro-orm-examples/tree/master/nest">Nest + MySQL + TypeScript</a></li>
Expand Down
12 changes: 6 additions & 6 deletions docs/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ console.log(author.books.contains(book)); // false
console.log(author.books.count()); // 0
console.log(author.books.getItems()); // Book[]
console.log(author.books.getIdentifiers()); // array of string | number
console.log(author.books.getIdentifiers('_id')); // array of ObjectID
console.log(author.books.getIdentifiers('_id')); // array of ObjectId

// array access works as well
console.log(author.books[1]); // Book
console.log(author.books[12345]); // undefined, even if the collection is not initialized
```

## OneToMany collections
## OneToMany Collections

`OneToMany` collections are inverse side of `ManyToOne` references, to which they need to point via `fk` attribute:

Expand All @@ -58,7 +58,7 @@ console.log(author.books[12345]); // undefined, even if the collection is not in
export class Book {

@PrimaryKey()
_id: ObjectID;
_id: ObjectId;

@ManyToOne()
author: Author;
Expand All @@ -69,18 +69,18 @@ export class Book {
export class Author {

@PrimaryKey()
_id: ObjectID;
_id: ObjectId;

@OneToMany({ entity: () => Book, mappedBy: 'author' })
books = new Collection<Book>(this);

}
```

## ManyToMany collections
## ManyToMany Collections

As opposed to SQL databases, with MongoDB we do not need to have join tables for `ManyToMany` relations.
All references are stored as an array of `ObjectID`s on owning entity.
All references are stored as an array of `ObjectId`s on owning entity.

### Unidirectional

Expand Down
2 changes: 1 addition & 1 deletion docs/custom-driver.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
---

# Creating custom driver
# Creating Custom Driver

If you want to use database that is not currently supported, you can implement your own driver.
To do so, you will need to design 4 classes:
Expand Down
47 changes: 35 additions & 12 deletions docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,51 @@ For development purposes it might come handy to enable logging and debug mode:

```typescript
return MikroORM.init({
logger: console.log.bind(console),
debug: true,
});
```

By doing this `MikroORM` will start using provided logger function to dump all queries:
By doing this `MikroORM` will start using `console.log()` function to dump all queries:

```
[query-logger] SELECT `e0`.* FROM `author` AS `e0` WHERE `e0`.`name` = ? LIMIT ? [took 2 ms]
[query-logger] START TRANSACTION [took 1 ms]
[query-logger] INSERT INTO `author` (`name`, `email`, `created_at`, `updated_at`, `terms_accepted`) VALUES (?, ?, ?, ?, ?) [took 2 ms]
[query-logger] COMMIT [took 2 ms]
[query] select `e0`.* from `author` as `e0` where `e0`.`name` = ? limit ? [took 2 ms]
[query] begin [took 1 ms]
[query] insert into `author` (`name`, `email`, `created_at`, `updated_at`, `terms_accepted`) values (?, ?, ?, ?, ?) [took 2 ms]
[query] commit [took 2 ms]
```

It is also useful for debugging problems with entity discovery, as you will see information
about every processed entity:

```
ORM entity discovery started
- processing entity Author
- using cached metadata for entity Author
- processing entity Book
- processing entity BookTag
- entity discovery finished after 13 ms
[discovery] ORM entity discovery started
[discovery] - processing entity Author
[discovery] - using cached metadata for entity Author
[discovery] - processing entity Book
[discovery] - processing entity BookTag
[discovery] - entity discovery finished after 13 ms
```

## Custom Logger

You can also provide your own logger via `logger` option.

```typescript
return MikroORM.init({
debug: true,
logger: msg => myCustomLogger.log(msg),
});
```

## Logger Namespaces

There are multiple Logger Namespaces that you can specifically request, while omitting the rest.
Just specify array of them via the `debug` option:

```typescript
return MikroORM.init({
debug: ['query'], // now only queries will be logged
});
```

Currently there are 3 namespaces – `query`, `discovery` and `info`.

0 comments on commit 8d300e6

Please sign in to comment.