mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
lint: fix offenses for @typescript-eslint/no-unused-vars rule in samples folder (#11757)
This commit is contained in:
parent
b639d33aee
commit
69dfc42eb9
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { Image } from "./entity/Image"
|
||||
@ -49,136 +49,7 @@ dataSource
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((result) => {
|
||||
/*const qb = postRepository.createQueryBuilder("post")
|
||||
.leftJoinAndSelect("post.details", "details")
|
||||
.leftJoinAndSelect("post.images", "images")
|
||||
// .leftJoinAndSelect("post.coverId", "coverId")
|
||||
.leftJoinAndSelect("post.categories", "categories")
|
||||
.where("post.id=:id")
|
||||
.setParameter("id", 6);
|
||||
|
||||
return qb
|
||||
.getSingleResult()
|
||||
.then(post => {
|
||||
console.log("loaded post: ", post);
|
||||
|
||||
let category1 = new Category();
|
||||
category1.id = 12;
|
||||
category1.description = "about cat#12";
|
||||
|
||||
let category2 = new Category();
|
||||
category2.id = 52;
|
||||
category2.description = "about cat#52";
|
||||
|
||||
let image = new Image();
|
||||
image.name = "second image of the post";
|
||||
|
||||
//post
|
||||
post.title = "This! is updated post$";
|
||||
post.text = "Hello world of post#4";
|
||||
post.categories = [category2, category1];
|
||||
post.images.push(image);
|
||||
return postRepository.save(post);
|
||||
|
||||
})
|
||||
.then(() => qb.getSingleResult())
|
||||
.then(reloadedPost => console.log("reloadedPost: ", reloadedPost));*/
|
||||
})
|
||||
.then((result) => console.log(result))
|
||||
.catch((error) => console.log(error.stack ? error.stack : error))
|
||||
|
||||
return
|
||||
|
||||
/*const postJson = {
|
||||
id: 1, // changed
|
||||
text: "This is post about hello", // changed
|
||||
title: "hello", // changed
|
||||
details: { // new relation added
|
||||
id: 10, // new object persisted
|
||||
comment: "This is post about hello",
|
||||
meta: "about-hello!",
|
||||
chapter: {
|
||||
id: 1, // new object persisted
|
||||
about: "part I"
|
||||
},
|
||||
categories: [{
|
||||
id: 5, // new object persisted
|
||||
description: "cat5"
|
||||
}]
|
||||
},
|
||||
cover: null, // relation removed
|
||||
images: [{ // new relation added
|
||||
id: 4, // new object persisted
|
||||
name: "post!.jpg",
|
||||
secondaryPost: {
|
||||
id: 2,
|
||||
title: "secondary post"
|
||||
}
|
||||
}, { // secondaryPost relation removed
|
||||
id: 3,
|
||||
name: "post_2!.jpg", // changed
|
||||
details: { // new relation added
|
||||
id: 3, // new object persisted
|
||||
meta: "sec image",
|
||||
comment: "image sec"
|
||||
}
|
||||
}],
|
||||
categories: [{ // two categories removed, new category added
|
||||
id: 4, // new persisted
|
||||
description: "cat2"
|
||||
}]
|
||||
};
|
||||
|
||||
let entity = postRepository.create(postJson);
|
||||
return postRepository.initialize(postJson)
|
||||
.then(result => {
|
||||
const mergedEntity = postRepository.merge(result, entity);
|
||||
console.log("entity created from json: ", entity);
|
||||
console.log("entity initialized from db: ", result);
|
||||
console.log("entity merged: ", mergedEntity);
|
||||
const diff = postRepository.difference(result, mergedEntity);
|
||||
console.log("diff: ", diff);
|
||||
//console.log("diff[0]: ", diff[0].removedRelations);
|
||||
})
|
||||
.catch(error => console.log(error.stack ? error.stack : error));
|
||||
|
||||
let qb = postRepository
|
||||
.createQueryBuilder("post")
|
||||
.addSelect("cover")
|
||||
.addSelect("image")
|
||||
.addSelect("imageDetails")
|
||||
.addSelect("secondaryImage")
|
||||
.addSelect("category")
|
||||
.innerJoin("post.coverId", "cover")
|
||||
.leftJoin("post.images", "image")
|
||||
.leftJoin("post.secondaryImages", "secondaryImage")
|
||||
.leftJoin("image.details", "imageDetails", "on", "imageDetails.meta=:meta")
|
||||
.leftJoin("post.categories", "category", "on", "category.description=:description")
|
||||
//.leftJoin(Image, "image", "on", "image.post=post.id")
|
||||
//.where("post.id=:id")
|
||||
.setParameter("id", 1)
|
||||
.setParameter("description", "cat2")
|
||||
.setParameter("meta", "sec image");
|
||||
|
||||
return qb
|
||||
.getSingleResult()
|
||||
.then(post => console.log(post))
|
||||
// .then(result => console.log(JSON.stringify(result, null, 4)))
|
||||
.catch(error => console.log(error.stack ? error.stack : error));*/
|
||||
|
||||
/*let details = new PostDetails();
|
||||
details.comment = "This is post about hello";
|
||||
details.meta = "about-hello";
|
||||
|
||||
const post = new Post();
|
||||
post.text = "Hello how are you?";
|
||||
post.title = "hello";
|
||||
//post.details = details;
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then(post => console.log("Post has been saved"))
|
||||
.catch(error => console.log("Cannot save. Error: ", error));*/
|
||||
})
|
||||
.catch((error) => console.log(error.stack ? error.stack : error))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { EverythingEntity, SampleEnum } from "./entity/EverythingEntity"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -99,7 +99,7 @@ dataSource.initialize().then(
|
||||
console.log("Now remove it")
|
||||
return postRepository.remove(entity!)
|
||||
})
|
||||
.then((entity) => {
|
||||
.then(() => {
|
||||
console.log("Entity has been removed")
|
||||
})
|
||||
.catch((error) =>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { CustomNamingStrategy } from "./naming-strategy/CustomNamingStrategy"
|
||||
|
||||
@ -26,7 +26,7 @@ dataSource.initialize().then(
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => console.log("Post has been saved"))
|
||||
.then(() => console.log("Post has been saved"))
|
||||
.catch((error) => console.log("Cannot save. Error: ", error))
|
||||
},
|
||||
(error) => console.log("Cannot connect: ", error),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
|
||||
@ -9,7 +9,7 @@ export class Blog extends BaseObject {
|
||||
@Column()
|
||||
text: string
|
||||
|
||||
@ManyToMany((type) => PostCategory, (category) => category.posts, {
|
||||
@ManyToMany(() => PostCategory, (category) => category.posts, {
|
||||
cascade: true,
|
||||
})
|
||||
@JoinTable()
|
||||
|
||||
@ -9,7 +9,7 @@ export class Post extends BaseObject {
|
||||
@Column()
|
||||
text: string
|
||||
|
||||
@ManyToMany((type) => PostCategory, (category) => category.posts, {
|
||||
@ManyToMany(() => PostCategory, (category) => category.posts, {
|
||||
cascade: true,
|
||||
})
|
||||
@JoinTable()
|
||||
|
||||
@ -10,7 +10,7 @@ export class PostCategory {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories, {
|
||||
@ManyToMany(() => Post, (post) => post.categories, {
|
||||
cascade: true,
|
||||
})
|
||||
posts: Post[] = []
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
|
||||
@ -29,7 +29,7 @@ dataSource.initialize().then(
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => console.log("Post has been saved"))
|
||||
.then(() => console.log("Post has been saved"))
|
||||
.catch((error) => console.log("Cannot save. Error: ", error))
|
||||
},
|
||||
(error) => console.log("Cannot connect: ", error),
|
||||
|
||||
@ -35,7 +35,7 @@ export class Post {
|
||||
// @JoinTable() // uncomment this and you'll get an error because JoinTable is not allowed here (only many-to-many)
|
||||
editors: PostAuthor[]
|
||||
|
||||
@ManyToMany((type) => PostAuthor, (author) => author.manyPosts)
|
||||
@ManyToMany(() => PostAuthor, (author) => author.manyPosts)
|
||||
@JoinTable() // comment this and you'll get an error because JoinTable must be at least on one side of the many-to-many relationship
|
||||
manyAuthors: PostAuthor[]
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { BasePost } from "./entity/BasePost"
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -47,13 +47,13 @@ dataSource.initialize().then(
|
||||
|
||||
return authorRepository.save(author)
|
||||
})
|
||||
.then((author: any) => {
|
||||
.then((author) => {
|
||||
// temporary
|
||||
console.log(
|
||||
"Author with a new post has been saved. Lets try to update post in the author",
|
||||
)
|
||||
|
||||
return author.posts!.then((posts: any) => {
|
||||
return author.posts!.then((posts) => {
|
||||
// temporary
|
||||
posts![0]!.title = "should be updated second post"
|
||||
return authorRepository.save(author!)
|
||||
@ -76,7 +76,7 @@ dataSource.initialize().then(
|
||||
posts[1].author = Promise.resolve(null)
|
||||
return postRepository.save(posts[0])
|
||||
})
|
||||
.then((posts) => {
|
||||
.then(() => {
|
||||
console.log("Two post's author has been removed.")
|
||||
console.log("Now lets check many-to-many relations")
|
||||
|
||||
@ -93,7 +93,7 @@ dataSource.initialize().then(
|
||||
|
||||
return postRepository.save(post)
|
||||
})
|
||||
.then((posts) => {
|
||||
.then(() => {
|
||||
console.log("Post has been saved with its categories. ")
|
||||
console.log("Lets find it now. ")
|
||||
return postRepository.find({
|
||||
@ -106,14 +106,13 @@ dataSource.initialize().then(
|
||||
.then((posts) => {
|
||||
console.log("Post with categories are loaded: ", posts)
|
||||
console.log("Lets remove one of the categories: ")
|
||||
return posts[0].categories.then((categories: any) => {
|
||||
return posts[0].categories.then((categories) => {
|
||||
// temporary
|
||||
categories!.splice(0, 1)
|
||||
// console.log(posts[0]);
|
||||
return postRepository.save(posts[0])
|
||||
})
|
||||
})
|
||||
.then((posts) => {
|
||||
.then(() => {
|
||||
console.log("One of the post category has been removed.")
|
||||
})
|
||||
.catch((error) => console.log(error.stack))
|
||||
|
||||
@ -10,6 +10,6 @@ export class Category {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories)
|
||||
@ManyToMany(() => Post, (post) => post.categories)
|
||||
posts: Promise<Post[]>
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -61,70 +61,10 @@ dataSource.initialize().then(
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// let secondPost = postRepository.create();
|
||||
// secondPost.text = "Second post";
|
||||
// secondPost.title = "About second post";
|
||||
// return authorRepository.save(author);
|
||||
})
|
||||
.then((post) => {
|
||||
console.log("Loaded posts: ", post)
|
||||
})
|
||||
/* posts[0].title = "should be updated second post";
|
||||
|
||||
return author.posts.then(posts => {
|
||||
return authorRepository.save(author);
|
||||
});
|
||||
})
|
||||
.then(updatedAuthor => {
|
||||
console.log("Author has been updated: ", updatedAuthor);
|
||||
console.log("Now lets load all posts with their authors:");
|
||||
return postRepository.find({ alias: "post", leftJoinAndSelect: { author: "post.author" } });
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Posts are loaded: ", posts);
|
||||
console.log("Now lets delete a post");
|
||||
posts[0].author = Promise.resolve(null);
|
||||
posts[1].author = Promise.resolve(null);
|
||||
return postRepository.save(posts[0]);
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Two post's author has been removed.");
|
||||
console.log("Now lets check many-to-many relations");
|
||||
|
||||
let category1 = categoryRepository.create();
|
||||
category1.name = "Hello category1";
|
||||
|
||||
let category2 = categoryRepository.create();
|
||||
category2.name = "Bye category2";
|
||||
|
||||
let post = postRepository.create();
|
||||
post.title = "Post & Categories";
|
||||
post.text = "Post with many categories";
|
||||
post.categories = Promise.resolve([
|
||||
category1,
|
||||
category2
|
||||
]);
|
||||
|
||||
return postRepository.save(post);
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Post has been saved with its categories. ");
|
||||
console.log("Lets find it now. ");
|
||||
return postRepository.find({ alias: "post", innerJoinAndSelect: { categories: "post.categories" } });
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Post with categories are loaded: ", posts);
|
||||
console.log("Lets remove one of the categories: ");
|
||||
return posts[0].categories.then(categories => {
|
||||
categories.splice(0, 1);
|
||||
// console.log(posts[0]);
|
||||
return postRepository.save(posts[0]);
|
||||
});
|
||||
})*/
|
||||
.then((posts) => {
|
||||
// console.log("One of the post category has been removed.");
|
||||
})
|
||||
.catch((error) => console.log(error.stack))
|
||||
},
|
||||
(error) => console.log("Cannot connect: ", error),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
@ -45,7 +45,7 @@ dataSource.initialize().then(
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => {
|
||||
.then(() => {
|
||||
console.log(
|
||||
"Post has been saved. Lets try to find this post using query builder: ",
|
||||
)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -38,7 +38,6 @@ dataSource.initialize().then(
|
||||
post.text = "Hello how are you?"
|
||||
post.title = "hello"
|
||||
post.authorId = 1
|
||||
// post.author = author;
|
||||
post.categories = [category1, category2]
|
||||
|
||||
Promise.all<any>([
|
||||
@ -78,61 +77,6 @@ dataSource.initialize().then(
|
||||
.then((authors) => {
|
||||
console.log("Loaded authors: ", authors)
|
||||
})
|
||||
/* posts[0].title = "should be updated second post";
|
||||
|
||||
return author.posts.then(posts => {
|
||||
return authorRepository.save(author);
|
||||
});
|
||||
})
|
||||
.then(updatedAuthor => {
|
||||
console.log("Author has been updated: ", updatedAuthor);
|
||||
console.log("Now lets load all posts with their authors:");
|
||||
return postRepository.find({ alias: "post", leftJoinAndSelect: { author: "post.author" } });
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Posts are loaded: ", posts);
|
||||
console.log("Now lets delete a post");
|
||||
posts[0].author = Promise.resolve(null);
|
||||
posts[1].author = Promise.resolve(null);
|
||||
return postRepository.save(posts[0]);
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Two post's author has been removed.");
|
||||
console.log("Now lets check many-to-many relations");
|
||||
|
||||
let category1 = categoryRepository.create();
|
||||
category1.name = "Hello category1";
|
||||
|
||||
let category2 = categoryRepository.create();
|
||||
category2.name = "Bye category2";
|
||||
|
||||
let post = postRepository.create();
|
||||
post.title = "Post & Categories";
|
||||
post.text = "Post with many categories";
|
||||
post.categories = Promise.resolve([
|
||||
category1,
|
||||
category2
|
||||
]);
|
||||
|
||||
return postRepository.save(post);
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Post has been saved with its categories. ");
|
||||
console.log("Lets find it now. ");
|
||||
return postRepository.find({ alias: "post", innerJoinAndSelect: { categories: "post.categories" } });
|
||||
})
|
||||
.then(posts => {
|
||||
console.log("Post with categories are loaded: ", posts);
|
||||
console.log("Lets remove one of the categories: ");
|
||||
return posts[0].categories.then(categories => {
|
||||
categories.splice(0, 1);
|
||||
// console.log(posts[0]);
|
||||
return postRepository.save(posts[0]);
|
||||
});
|
||||
})*/
|
||||
.then((posts) => {
|
||||
// console.log("One of the post category has been removed.");
|
||||
})
|
||||
.catch((error) => console.log(error.stack))
|
||||
},
|
||||
(error) => console.log("Cannot connect: ", error),
|
||||
|
||||
@ -18,7 +18,7 @@ export class Post {
|
||||
@Column("int")
|
||||
authorId: number
|
||||
|
||||
@ManyToMany((type) => Category)
|
||||
@ManyToMany(() => Category)
|
||||
@JoinTable()
|
||||
categories: Category[]
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -38,7 +38,7 @@ dataSource.initialize().then(
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => {
|
||||
.then(() => {
|
||||
console.log("Post has been saved. Lets load it now.")
|
||||
return postRepository.find({
|
||||
join: {
|
||||
|
||||
@ -10,6 +10,6 @@ export class Category {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories)
|
||||
@ManyToMany(() => Post, (post) => post.categories)
|
||||
posts: Post[]
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -39,7 +39,7 @@ dataSource.initialize().then(
|
||||
|
||||
return categoryRepository
|
||||
.save(category1)
|
||||
.then((category) => {
|
||||
.then(() => {
|
||||
console.log(
|
||||
"Categories has been saved. Lets now load it and all its descendants:",
|
||||
)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -41,7 +41,7 @@ dataSource.initialize().then(
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => {
|
||||
.then(() => {
|
||||
return postRepository
|
||||
.createQueryBuilder("post")
|
||||
.leftJoin("post.categories", "categories")
|
||||
@ -63,7 +63,7 @@ dataSource.initialize().then(
|
||||
|
||||
return postRepository.save(post)
|
||||
})
|
||||
.then((updatedPost) => {
|
||||
.then(() => {
|
||||
return postRepository
|
||||
.createQueryBuilder("post")
|
||||
.leftJoinAndSelect("post.author", "author")
|
||||
@ -80,7 +80,7 @@ dataSource.initialize().then(
|
||||
loadedPost!.author = author
|
||||
return postRepository.save(loadedPost!)
|
||||
})
|
||||
.then((updatedPost) => {
|
||||
.then(() => {
|
||||
return postRepository
|
||||
.createQueryBuilder("post")
|
||||
.leftJoinAndSelect("post.author", "author")
|
||||
@ -94,7 +94,7 @@ dataSource.initialize().then(
|
||||
post.author = null
|
||||
return postRepository.save(post)
|
||||
})
|
||||
.then((updatedPost) => {
|
||||
.then(() => {
|
||||
return postRepository
|
||||
.createQueryBuilder("post")
|
||||
.leftJoinAndSelect("post.author", "author")
|
||||
@ -106,7 +106,7 @@ dataSource.initialize().then(
|
||||
post.author = author2
|
||||
return postRepository.save(post)
|
||||
})
|
||||
.then((updatedPost) => {
|
||||
.then(() => {
|
||||
return postRepository
|
||||
.createQueryBuilder("post")
|
||||
.leftJoinAndSelect("post.author", "author")
|
||||
|
||||
@ -11,7 +11,7 @@ export class Category {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Author)
|
||||
@ManyToMany(() => Author)
|
||||
@JoinTable()
|
||||
author: Author
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
|
||||
@ -27,7 +27,7 @@ dataSource.initialize().then(
|
||||
if (!author) {
|
||||
author = new Author()
|
||||
author.name = "Umed"
|
||||
return authorRepository.save(author).then((savedAuthor) => {
|
||||
return authorRepository.save(author).then(() => {
|
||||
return authorRepository.findOneBy({ id: 1 })
|
||||
})
|
||||
}
|
||||
@ -39,7 +39,7 @@ dataSource.initialize().then(
|
||||
post = new Post()
|
||||
post.title = "Hello post"
|
||||
post.text = "This is post contents"
|
||||
return postRepository.save(post).then((savedPost) => {
|
||||
return postRepository.save(post).then(() => {
|
||||
return postRepository.findOneBy({ id: 1 })
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Question } from "./entity/Question"
|
||||
import { Counters } from "./entity/Counters"
|
||||
|
||||
@ -12,6 +12,6 @@ export class Post {
|
||||
@Column()
|
||||
text: string
|
||||
|
||||
@Column((type) => Counters)
|
||||
@Column(() => Counters)
|
||||
counters: Counters
|
||||
}
|
||||
|
||||
@ -9,6 +9,6 @@ export class Question {
|
||||
@Column()
|
||||
title: string
|
||||
|
||||
@Column((type) => Counters)
|
||||
@Column(() => Counters)
|
||||
counters: Counters
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Employee } from "./entity/Employee"
|
||||
import { Homesitter } from "./entity/Homesitter"
|
||||
import { Student } from "./entity/Student"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
@ -9,11 +9,6 @@ import { PostInformation } from "./entity/PostInformation"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
// type: "mssql",
|
||||
// host: "192.168.1.10",
|
||||
// username: "sa",
|
||||
// password: "admin12345",
|
||||
// database: "test",
|
||||
type: "oracle",
|
||||
host: "localhost",
|
||||
username: "system",
|
||||
@ -51,7 +46,7 @@ dataSource
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => console.log("Post has been saved"))
|
||||
.then(() => console.log("Post has been saved"))
|
||||
.catch((error) => console.log("Cannot save. Error: ", error))
|
||||
})
|
||||
.catch((error) => console.log("Error: ", error))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ export class Post {
|
||||
@Column()
|
||||
text: string
|
||||
|
||||
@ManyToMany((type) => Category)
|
||||
@ManyToMany(() => Category)
|
||||
@JoinTable()
|
||||
categories: Category[]
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
|
||||
@ -32,7 +32,7 @@ dataSource.initialize().then(
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
.then((post) => console.log("Post has been saved"))
|
||||
.then(() => console.log("Post has been saved"))
|
||||
.catch((error) => console.log("Cannot save. Error: ", error))
|
||||
},
|
||||
(error) => console.log("Cannot connect: ", error),
|
||||
|
||||
@ -25,7 +25,7 @@ export class Post {
|
||||
|
||||
// Post has relation with PostCategory, however inverse relation is not set
|
||||
// (category does not have relation with post set)
|
||||
@ManyToMany((type) => PostCategory, {
|
||||
@ManyToMany(() => PostCategory, {
|
||||
cascade: true,
|
||||
})
|
||||
@JoinTable()
|
||||
@ -33,7 +33,7 @@ export class Post {
|
||||
|
||||
// Post has relation with PostDetails. Cascade insert here means if there is a new PostDetails instance set
|
||||
// on this relation, it will be inserted automatically to the db when you save this Post entity
|
||||
@ManyToMany((type) => PostDetails, (details) => details.posts, {
|
||||
@ManyToMany(() => PostDetails, (details) => details.posts, {
|
||||
cascade: ["insert"],
|
||||
})
|
||||
@JoinTable()
|
||||
@ -41,7 +41,7 @@ export class Post {
|
||||
|
||||
// Post has relation with PostImage. Cascade update here means if there are changes to an existing PostImage, it
|
||||
// will be updated automatically to the db when you save this Post entity
|
||||
@ManyToMany((type) => PostImage, (image) => image.posts, {
|
||||
@ManyToMany(() => PostImage, (image) => image.posts, {
|
||||
cascade: ["update"],
|
||||
})
|
||||
@JoinTable()
|
||||
@ -49,12 +49,12 @@ export class Post {
|
||||
|
||||
// Post has relation with PostMetadata. No cascades here means that when saving a Post entity, there will be
|
||||
// no creating/updating/destroying PostMetadata.
|
||||
@ManyToMany((type) => PostMetadata, (metadata) => metadata.posts)
|
||||
@ManyToMany(() => PostMetadata, (metadata) => metadata.posts)
|
||||
@JoinTable()
|
||||
metadatas: PostMetadata[]
|
||||
|
||||
// Post has relation with PostInformation. Full cascades here
|
||||
@ManyToMany((type) => PostInformation, (information) => information.posts, {
|
||||
@ManyToMany(() => PostInformation, (information) => information.posts, {
|
||||
cascade: true,
|
||||
})
|
||||
@JoinTable()
|
||||
@ -62,7 +62,7 @@ export class Post {
|
||||
|
||||
// Post has relation with author. No cascades here means that when saving a Post entity, there will be
|
||||
// no creating/updating/destroying PostAuthor.
|
||||
@ManyToMany((type) => PostAuthor, (author) => author.posts)
|
||||
@ManyToMany(() => PostAuthor, (author) => author.posts)
|
||||
@JoinTable()
|
||||
authors: PostAuthor[]
|
||||
}
|
||||
|
||||
@ -14,6 +14,6 @@ export class PostAuthor {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.authors)
|
||||
@ManyToMany(() => Post, (post) => post.authors)
|
||||
posts: Post[]
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ export class PostDetails {
|
||||
})
|
||||
metadata: string | null
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.details, {
|
||||
@ManyToMany(() => Post, (post) => post.details, {
|
||||
cascade: true,
|
||||
})
|
||||
posts: Post[]
|
||||
|
||||
@ -14,6 +14,6 @@ export class PostImage {
|
||||
@Column()
|
||||
url: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.images)
|
||||
@ManyToMany(() => Post, (post) => post.images)
|
||||
posts: Post[]
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ export class PostInformation {
|
||||
@Column()
|
||||
text: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.informations, {
|
||||
@ManyToMany(() => Post, (post) => post.informations, {
|
||||
cascade: ["update"],
|
||||
})
|
||||
posts: Post[]
|
||||
|
||||
@ -14,6 +14,6 @@ export class PostMetadata {
|
||||
@Column()
|
||||
description: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.metadatas)
|
||||
@ManyToMany(() => Post, (post) => post.metadatas)
|
||||
posts: Post[]
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -66,7 +66,7 @@ dataSource.initialize().then(
|
||||
console.log("update finished. Now lets remove entity")
|
||||
return postRepository.remove(loadedPost)
|
||||
})
|
||||
.then((loadedPost) => {
|
||||
.then(() => {
|
||||
console.log("---------------------------")
|
||||
console.log("post removed.")
|
||||
})
|
||||
|
||||
@ -10,7 +10,7 @@ export class PostCategory {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories, {
|
||||
@ManyToMany(() => Post, (post) => post.categories, {
|
||||
cascade: true,
|
||||
})
|
||||
posts: Post[] = []
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
|
||||
@ -10,7 +10,7 @@ export class PostCategory {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories, {
|
||||
@ManyToMany(() => Post, (post) => post.categories, {
|
||||
cascade: true,
|
||||
})
|
||||
posts: Post[] = []
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -48,7 +48,7 @@ dataSource.initialize().then(
|
||||
.take(10)
|
||||
|
||||
Promise.all(posts.map((post) => postRepository.save(post)))
|
||||
.then((savedPosts) => {
|
||||
.then(() => {
|
||||
console.log("Posts has been saved. Lets try to load some posts")
|
||||
return qb.getMany()
|
||||
})
|
||||
|
||||
@ -10,7 +10,7 @@ export class PostCategory {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories, {
|
||||
@ManyToMany(() => Post, (post) => post.categories, {
|
||||
cascade: true,
|
||||
})
|
||||
posts: Post[] = []
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -66,7 +66,7 @@ dataSource.initialize().then(
|
||||
console.log("---------------------------")
|
||||
return postRepository.remove(loadedPost)
|
||||
})
|
||||
.then((loadedPost) => {
|
||||
.then(() => {
|
||||
console.log("post removed.")
|
||||
})
|
||||
.catch((error) =>
|
||||
|
||||
@ -20,7 +20,7 @@ export class PostCategory {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany((type) => Post, (post) => post.categories, {
|
||||
@ManyToMany(() => Post, (post) => post.categories, {
|
||||
cascade: true,
|
||||
})
|
||||
posts: Post[] = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user