forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic mongodb support, mongodb repository, entity manager and a…
…ll major collection operations
- Loading branch information
Umed Khudoiberdiev
committed
Feb 11, 2017
1 parent
64d38e3
commit 5fcc3ae
Showing
72 changed files
with
3,037 additions
and
658 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ coverage/ | |
node_modules/ | ||
npm-debug.log | ||
ormconfig.json | ||
.vscode | ||
.vscode |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "reflect-metadata"; | ||
import {createConnection, ConnectionOptions} from "../../src/index"; | ||
import {Post} from "./entity/Post"; | ||
|
||
const options: ConnectionOptions = { | ||
driver: { | ||
type: "mongodb", | ||
host: "localhost", | ||
database: "test", | ||
}, | ||
logging: { | ||
logQueries: true, | ||
logSchemaCreation: true | ||
}, | ||
// autoSchemaSync: true, | ||
entities: [Post] | ||
}; | ||
|
||
createConnection(options).then(async connection => { | ||
|
||
const post = new Post(); | ||
post.text = "Hello how are you?"; | ||
post.title = "hello"; | ||
post.likesCount = 100; | ||
|
||
await connection.getRepository(Post).persist(post); | ||
console.log("Post has been saved: ", post); | ||
|
||
const loadedPost = await connection.getRepository(Post).findOne({ | ||
text: "Hello how are you?", | ||
}); | ||
console.log("Post has been loaded: ", loadedPost); | ||
|
||
// take last 5 of saved posts | ||
const allPosts = await connection.getRepository(Post).find({ take: 5 }); | ||
console.log("All posts: ", allPosts); | ||
|
||
// perform mongodb-specific query using cursor which returns properly initialized entities | ||
const cursor1 = connection.getMongoRepository(Post).createEntityCursor({ title: "hello" }); | ||
console.log("Post retrieved via cursor #1: ", await cursor1.next()); | ||
console.log("Post retrieved via cursor #2: ", await cursor1.next()); | ||
|
||
// we can also perform mongodb-specific queries using mongodb-specific entity manager | ||
const cursor2 = connection.mongoEntityManager.createEntityCursor(Post, { title: "hello" }); | ||
console.log("Only two posts retrieved via cursor: ", await cursor2.limit(2).toArray()); | ||
|
||
}, error => console.log("Error: ", error)); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {Column, Entity} from "../../../src/index"; | ||
import {ObjectIdColumn} from "../../../src/decorator/columns/ObjectIdColumn"; | ||
import {ObjectID} from "mongodb"; | ||
|
||
@Entity("sample34_post") | ||
export class Post { | ||
|
||
@ObjectIdColumn() | ||
id: ObjectID; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column() | ||
text: string; | ||
|
||
@Column("int", { | ||
nullable: false | ||
}) | ||
likesCount: number; | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.