Skip to content

Commit

Permalink
Merge c5a621f into c49e0e4
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Aug 16, 2019
2 parents c49e0e4 + c5a621f commit 59b0bf6
Show file tree
Hide file tree
Showing 112 changed files with 3,860 additions and 2,707 deletions.
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
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
8 changes: 4 additions & 4 deletions docs/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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
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,7 +69,7 @@ export class Book {
export class Author {

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

@OneToMany({ entity: () => Book, mappedBy: 'author' })
books = new Collection<Book>(this);
Expand All @@ -80,7 +80,7 @@ export class Author {
## 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
8 changes: 4 additions & 4 deletions docs/defining-entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ to [use entity constructors](entity-constructors.md), just do not forget to spec
export class Book {

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

@Property()
createdAt = new Date();
Expand Down Expand Up @@ -65,7 +65,7 @@ Here is another example of `Author` entity, that was referenced from the `Book`
export class Author {

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

@Property()
createdAt = new Date();
Expand Down Expand Up @@ -141,7 +141,7 @@ primary key and created/updated time.
export abstract class BaseEntity {

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

@Property()
createdAt = new Date();
Expand All @@ -154,7 +154,7 @@ export abstract class BaseEntity {

## Note about SQL drivers and @PrimaryKey

All entities described above were defined with `_id: ObjectID` primary key - those were Mongo
All entities described above were defined with `_id: ObjectId` primary key - those were Mongo
entities.

For SQL drivers, you will want to define your primary key as `id: number` instead:
Expand Down
2 changes: 1 addition & 1 deletion docs/entity-constructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ but `publisher` will be optional:
export class Book {

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

@Property()
title: string;
Expand Down
7 changes: 6 additions & 1 deletion docs/lifecycle-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
You can use lifecycle hooks to run some code when entity gets persisted. You can mark any of
entity methods with them, you can also mark multiple methods with same hook.

All hooks support async methods.
All hooks support async methods with one exception - `@OnInit`.

- `@OnInit` is fired when new instance of entity is created, either manually `em.create()`, or
automatically when new entities are loaded from database

- `@BeforeCreate()` and `@BeforeUpdate()` is fired right before we persist the entity in database

Expand All @@ -20,4 +23,6 @@ removing entity or entity reference, not when deleting records by query.
- `@AfterDelete()` is fired right after the record gets deleted from database and it is unset from
the identity map.

> `@OnInit` is not fired when you create the entity manually via its constructor (`new MyEntity()`)
[&larr; Back to table of contents](index.md#table-of-contents)
12 changes: 6 additions & 6 deletions docs/usage-with-mongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ When defining entity, do not forget to define primary key like this:

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

## ObjectID and string id duality
## ObjectId and string id duality

Every entity has both `ObjectID` and `string` id available, also all methods of `EntityManager`
Every entity has both `ObjectId` and `string` id available, also all methods of `EntityManager`
and `EntityRepository` supports querying by both of them.

```typescript
const author = orm.em.getReference('...id...');
console.log(author.id); // returns '...id...'
console.log(author._id); // returns ObjectID('...id...')
console.log(author._id); // returns ObjectId('...id...')

// all of those will return the same results
const article = '...article id...'; // string id
const book = '...book id...'; // string id
const repo = orm.em.getRepository(Author);
const foo1 = await repo.find({ id: { $in: [article] }, favouriteBook: book });
const bar1 = await repo.find({ id: { $in: [new ObjectID(article)] }, favouriteBook: new ObjectID(book) });
const bar1 = await repo.find({ id: { $in: [new ObjectId(article)] }, favouriteBook: new ObjectId(book) });
const foo2 = await repo.find({ _id: { $in: [article] }, favouriteBook: book });
const bar2 = await repo.find({ _id: { $in: [new ObjectID(article)] }, favouriteBook: new ObjectID(book) });
const bar2 = await repo.find({ _id: { $in: [new ObjectId(article)] }, favouriteBook: new ObjectId(book) });
```

## ManyToMany collections with inlined pivot array
Expand Down
Loading

0 comments on commit 59b0bf6

Please sign in to comment.