mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
remove globals usages
This commit is contained in:
parent
9d1e2460ed
commit
2205a1a6a5
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -15,14 +15,15 @@ const options: DataSourceOptions = {
|
||||
entities: [Post],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
async (connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
async (dataSource) => {
|
||||
let post = new Post()
|
||||
post.text = "Hello how are you?"
|
||||
post.title = "hello"
|
||||
post.likesCount = 100
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { Image } from "./entity/Image"
|
||||
@ -17,9 +17,11 @@ const options: DataSourceOptions = {
|
||||
entities: [__dirname + "/entity/*"],
|
||||
}
|
||||
|
||||
createConnection(options)
|
||||
.then((connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource
|
||||
.initialize()
|
||||
.then((dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
let postCover = new Cover()
|
||||
postCover.url = "http://covers.com/post.jpg"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { EverythingEntity, SampleEnum } from "./entity/EverythingEntity"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -14,8 +14,9 @@ const options: DataSourceOptions = {
|
||||
entities: [EverythingEntity],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let entity = new EverythingEntity()
|
||||
entity.date = new Date(1980, 11, 1)
|
||||
entity.name = "max 255 chars name"
|
||||
@ -38,7 +39,7 @@ createConnection(options).then(
|
||||
entity.alsoJson = { hello: "olleh", world: "dlrow" }
|
||||
entity.enum = SampleEnum.ONE
|
||||
|
||||
let postRepository = connection.getRepository(EverythingEntity)
|
||||
let postRepository = dataSource.getRepository(EverythingEntity)
|
||||
|
||||
postRepository
|
||||
.save(entity)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { CustomNamingStrategy } from "./naming-strategy/CustomNamingStrategy"
|
||||
|
||||
@ -15,13 +15,14 @@ const options: DataSourceOptions = {
|
||||
entities: [Post],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let post = new Post()
|
||||
post.text = "Hello how are you?"
|
||||
post.title = "hello"
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -17,8 +17,9 @@ const options: DataSourceOptions = {
|
||||
entities: [__dirname + "/entity/*"],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let category1 = new PostCategory()
|
||||
category1.name = "post category #1"
|
||||
|
||||
@ -53,8 +54,8 @@ createConnection(options).then(
|
||||
blog.title2312312 = "awesome title!"
|
||||
blog.categories.push(category1, category2)
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let blogRepository = connection.getRepository(Blog)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
let blogRepository = dataSource.getRepository(Blog)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
|
||||
@ -14,8 +14,9 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, PostAuthor],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let author = new PostAuthor()
|
||||
author.name = "Umed"
|
||||
|
||||
@ -24,7 +25,7 @@ createConnection(options).then(
|
||||
post.title = "hello"
|
||||
post.author = author
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { BasePost } from "./entity/BasePost"
|
||||
|
||||
@ -15,14 +15,15 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, BasePost],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let post = new Post()
|
||||
post.text = "Hello how are you?"
|
||||
post.title = "hello"
|
||||
post.likesCount = 0
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -14,13 +14,14 @@ const options: DataSourceOptions = {
|
||||
entities: [Post],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let post = new Post()
|
||||
post.text = "Hello how are you?"
|
||||
post.title = "hello"
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -16,11 +16,12 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author, Category],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let authorRepository = connection.getRepository(Author)
|
||||
let categoryRepository = connection.getRepository(Category)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
let authorRepository = dataSource.getRepository(Author)
|
||||
let categoryRepository = dataSource.getRepository(Category)
|
||||
|
||||
let author = authorRepository.create()
|
||||
author.name = "Umed"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -17,12 +17,13 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author, Category, PostMetadata],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let authorRepository = connection.getRepository(Author)
|
||||
let categoryRepository = connection.getRepository(Category)
|
||||
let metadataRepository = connection.getRepository(PostMetadata)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
let authorRepository = dataSource.getRepository(Author)
|
||||
let categoryRepository = dataSource.getRepository(Category)
|
||||
let metadataRepository = dataSource.getRepository(PostMetadata)
|
||||
|
||||
let category1 = categoryRepository.create()
|
||||
category1.name = "Hello category1"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
@ -28,8 +28,9 @@ const options: DataSourceOptions = {
|
||||
],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let details = new PostDetails()
|
||||
details.authorName = "Umed"
|
||||
details.comment = "about post"
|
||||
@ -40,7 +41,7 @@ createConnection(options).then(
|
||||
post.title = "hello"
|
||||
post.details = details
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -16,13 +16,14 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author, Category],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let entityManager = connection.manager
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let entityManager = dataSource.manager
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let authorRepository = connection.getRepository(Author)
|
||||
let categoryRepository = connection.getRepository(Category)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
let authorRepository = dataSource.getRepository(Author)
|
||||
let categoryRepository = dataSource.getRepository(Category)
|
||||
|
||||
let category1 = categoryRepository.create()
|
||||
category1.name = "Hello category1"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -16,9 +16,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author, Category],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
let author = new Author()
|
||||
author.name = "Umed"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -14,9 +14,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Category],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let categoryRepository = connection.getTreeRepository(Category)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let categoryRepository = dataSource.getTreeRepository(Category)
|
||||
|
||||
let childChildCategory1 = new Category()
|
||||
childChildCategory1.name = "Child #1 of Child #1 of Category #1"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -16,9 +16,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author, Category],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
let category1 = new Category()
|
||||
category1.name = "category #1"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection, EntitySchema } from "../../src"
|
||||
import { DataSource, DataSourceOptions, EntitySchema } from "../../src"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -36,9 +36,11 @@ const options: DataSourceOptions = {
|
||||
entities: [PostEntity, PostDetailsEntity, CategoryEntity, ImageEntity],
|
||||
}
|
||||
|
||||
createConnection(options)
|
||||
.then((connection) => {
|
||||
let postRepository = connection.getRepository<Post>("Post")
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource
|
||||
.initialize()
|
||||
.then((dataSource) => {
|
||||
let postRepository = dataSource.getRepository<Post>("Post")
|
||||
|
||||
let post: Post = {
|
||||
title: "Hello post",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
|
||||
@ -15,10 +15,11 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let authorRepository = connection.getRepository(Author)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
let authorRepository = dataSource.getRepository(Author)
|
||||
|
||||
const authorPromise = authorRepository
|
||||
.findOneBy({ id: 1 })
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Question } from "./entity/Question"
|
||||
import { Counters } from "./entity/Counters"
|
||||
@ -16,9 +16,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Question, Counters],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let questionRepository = connection.getRepository(Question)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let questionRepository = dataSource.getRepository(Question)
|
||||
|
||||
const question = new Question()
|
||||
question.title = "Hello question!"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -14,9 +14,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Post],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
async (connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
async (dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
const post = new Post()
|
||||
post.id = 1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Employee } from "./entity/Employee"
|
||||
import { Homesitter } from "./entity/Homesitter"
|
||||
import { Student } from "./entity/Student"
|
||||
@ -17,9 +17,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Person, Employee, Homesitter, Student],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
async (connection) => {
|
||||
let employeeRepository = connection.getRepository(Employee)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
async (dataSource) => {
|
||||
let employeeRepository = dataSource.getRepository(Employee)
|
||||
const employee = new Employee()
|
||||
employee.id = 1
|
||||
employee.firstName = "umed"
|
||||
@ -38,7 +39,7 @@ createConnection(options).then(
|
||||
|
||||
console.log("-----------------")
|
||||
|
||||
let homesitterRepository = connection.getRepository(Homesitter)
|
||||
let homesitterRepository = dataSource.getRepository(Homesitter)
|
||||
const homesitter = new Homesitter()
|
||||
homesitter.id = 2
|
||||
homesitter.firstName = "umed"
|
||||
@ -57,7 +58,7 @@ createConnection(options).then(
|
||||
|
||||
console.log("-----------------")
|
||||
|
||||
let studentRepository = connection.getRepository(Student)
|
||||
let studentRepository = dataSource.getRepository(Student)
|
||||
const student = new Student()
|
||||
student.id = 3
|
||||
student.firstName = "umed"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
@ -33,8 +33,10 @@ const options: DataSourceOptions = {
|
||||
],
|
||||
}
|
||||
|
||||
createConnection(options)
|
||||
.then((connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource
|
||||
.initialize()
|
||||
.then((dataSource) => {
|
||||
let details = new PostDetails()
|
||||
details.authorName = "Umed"
|
||||
details.comment = "about post"
|
||||
@ -45,7 +47,7 @@ createConnection(options)
|
||||
post.title = "hello"
|
||||
post.details = details
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
@ -11,9 +11,11 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Category],
|
||||
}
|
||||
|
||||
createConnection(options)
|
||||
.then(async (connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource
|
||||
.initialize()
|
||||
.then(async (dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
let post1 = new Post("Me", "hello me", [
|
||||
new Category("programming"),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
import { Category } from "./entity/Category"
|
||||
@ -13,8 +13,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author, Category],
|
||||
}
|
||||
|
||||
createConnection(options)
|
||||
.then(async (connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource
|
||||
.initialize()
|
||||
.then(async (dataSource) => {
|
||||
let category1 = new Category()
|
||||
category1.name = "Animals"
|
||||
|
||||
@ -31,7 +33,7 @@ createConnection(options)
|
||||
post.author = author
|
||||
post.categories = [category1, category2]
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
await postRepository.save(post)
|
||||
console.log("Post has been saved")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { Author } from "./entity/Author"
|
||||
|
||||
@ -15,8 +15,10 @@ const options: DataSourceOptions = {
|
||||
entities: [Post, Author],
|
||||
}
|
||||
|
||||
createConnection(options)
|
||||
.then(async (connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource
|
||||
.initialize()
|
||||
.then(async (dataSource) => {
|
||||
// first insert all the data
|
||||
let author = new Author()
|
||||
author.firstName = "Umed"
|
||||
@ -26,7 +28,7 @@ createConnection(options)
|
||||
post.title = "hello"
|
||||
post.author = author
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
await postRepository.save(post)
|
||||
console.log(
|
||||
@ -34,10 +36,10 @@ createConnection(options)
|
||||
)
|
||||
|
||||
// close connection now
|
||||
await connection.close()
|
||||
await dataSource.destroy()
|
||||
|
||||
// now create a new connection
|
||||
connection = await createConnection({
|
||||
// now re-initialize data source
|
||||
dataSource = new DataSource({
|
||||
type: "mysql",
|
||||
name: "mysql",
|
||||
host: "localhost",
|
||||
@ -49,13 +51,14 @@ createConnection(options)
|
||||
entities: [Post, Author],
|
||||
migrations: [__dirname + "/migrations/*{.js,.ts}"],
|
||||
})
|
||||
await dataSource.initialize()
|
||||
|
||||
// run all migrations
|
||||
await connection.runMigrations()
|
||||
await dataSource.runMigrations()
|
||||
|
||||
// and undo migrations two times (because we have two migrations)
|
||||
await connection.undoLastMigration()
|
||||
await connection.undoLastMigration()
|
||||
await dataSource.undoLastMigration()
|
||||
await dataSource.undoLastMigration()
|
||||
|
||||
console.log("Done. We run two migrations then reverted them.")
|
||||
})
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -11,34 +11,35 @@ const options: DataSourceOptions = {
|
||||
entities: [Post],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
async (connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
async (dataSource) => {
|
||||
const post = new Post()
|
||||
post.text = "Hello how are you?"
|
||||
post.title = "hello"
|
||||
post.likesCount = 100
|
||||
|
||||
await connection.getRepository(Post).save(post)
|
||||
await dataSource.getRepository(Post).save(post)
|
||||
console.log("Post has been saved: ", post)
|
||||
|
||||
const loadedPost = await connection.getRepository(Post).findOneBy({
|
||||
const loadedPost = await dataSource.getRepository(Post).findOneBy({
|
||||
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 })
|
||||
const allPosts = await dataSource.getRepository(Post).find({ take: 5 })
|
||||
console.log("All posts: ", allPosts)
|
||||
|
||||
// perform mongodb-specific query using cursor which returns properly initialized entities
|
||||
const cursor1 = connection
|
||||
const cursor1 = dataSource
|
||||
.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.mongoManager.createEntityCursor(Post, {
|
||||
const cursor2 = dataSource.mongoManager.createEntityCursor(Post, {
|
||||
title: "hello",
|
||||
})
|
||||
console.log(
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostDetails } from "./entity/PostDetails"
|
||||
|
||||
@ -14,8 +14,9 @@ const options: DataSourceOptions = {
|
||||
entities: [__dirname + "/entity/*"],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let details1 = new PostDetails()
|
||||
details1.comment = "People"
|
||||
|
||||
@ -27,7 +28,7 @@ createConnection(options).then(
|
||||
post.title = "hello"
|
||||
post.details = [details1, details2]
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -18,8 +18,9 @@ const options: DataSourceOptions = {
|
||||
subscribers: [EverythingSubscriber],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let category1 = new PostCategory()
|
||||
category1.name = "post category #1"
|
||||
|
||||
@ -35,7 +36,7 @@ createConnection(options).then(
|
||||
post.categories.push(category1, category2)
|
||||
post.author = author
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -16,8 +16,9 @@ const options: DataSourceOptions = {
|
||||
entities: [__dirname + "/entity/*"],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let category1 = new PostCategory()
|
||||
category1.name = "post category #1"
|
||||
|
||||
@ -48,8 +49,8 @@ createConnection(options).then(
|
||||
blog.author = author
|
||||
blog.categories.push(category1, category2)
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let blogRepository = connection.getRepository(Blog)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
let blogRepository = dataSource.getRepository(Blog)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -15,9 +15,10 @@ const options: DataSourceOptions = {
|
||||
entities: [__dirname + "/entity/*"],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let postRepository = connection.getRepository(Post)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
const posts: Post[] = []
|
||||
|
||||
let author = new PostAuthor()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Category } from "./entity/Category"
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
@ -13,9 +13,10 @@ const options: DataSourceOptions = {
|
||||
entities: [__dirname + "/entity/*"],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
let categoryRepository = connection.getRepository(Category)
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let categoryRepository = dataSource.getRepository(Category)
|
||||
|
||||
let category1 = new Category()
|
||||
category1.name = "category #1"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSourceOptions, createConnection } from "../../src/index"
|
||||
import { DataSource, DataSourceOptions } from "../../src/index"
|
||||
import { Post } from "./entity/Post"
|
||||
import { PostCategory } from "./entity/PostCategory"
|
||||
import { PostAuthor } from "./entity/PostAuthor"
|
||||
@ -16,8 +16,9 @@ const options: DataSourceOptions = {
|
||||
subscribers: [__dirname + "/subscriber/*"],
|
||||
}
|
||||
|
||||
createConnection(options).then(
|
||||
(connection) => {
|
||||
const dataSource = new DataSource(options)
|
||||
dataSource.initialize().then(
|
||||
(dataSource) => {
|
||||
let category1 = new PostCategory()
|
||||
category1.name = "post category #1"
|
||||
|
||||
@ -33,7 +34,7 @@ createConnection(options).then(
|
||||
post.categories.push(category1, category2)
|
||||
post.author = author
|
||||
|
||||
let postRepository = connection.getRepository(Post)
|
||||
let postRepository = dataSource.getRepository(Post)
|
||||
|
||||
postRepository
|
||||
.save(post)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import "reflect-metadata"
|
||||
import * as fs from "fs"
|
||||
import { expect } from "chai"
|
||||
import { getSqljsManager } from "../../../src/index"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
@ -26,13 +25,12 @@ describe("sqljs driver > load", () => {
|
||||
|
||||
it("should load from a file", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const manager = getSqljsManager("sqljs")
|
||||
await manager.loadDatabase(
|
||||
connections.map(async (dataSource) => {
|
||||
await dataSource.sqljsManager.loadDatabase(
|
||||
"test/functional/sqljs/sqlite/test.sqlite",
|
||||
)
|
||||
|
||||
const repository = connection.getRepository(Post)
|
||||
const repository = dataSource.getRepository(Post)
|
||||
const post = await repository.findOneBy({ title: "A post" })
|
||||
|
||||
expect(post).not.to.be.null
|
||||
@ -40,7 +38,8 @@ describe("sqljs driver > load", () => {
|
||||
expect(post.title).to.be.equal("A post")
|
||||
}
|
||||
|
||||
const exportedDatabase = manager.exportDatabase()
|
||||
const exportedDatabase =
|
||||
dataSource.sqljsManager.exportDatabase()
|
||||
expect(exportedDatabase).not.to.be.undefined
|
||||
const originalFileContent = fs.readFileSync(
|
||||
"test/functional/sqljs/sqlite/test.sqlite",
|
||||
@ -53,10 +52,9 @@ describe("sqljs driver > load", () => {
|
||||
|
||||
it("should throw an error if the file doesn't exist", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const manager = getSqljsManager("sqljs")
|
||||
connections.map(async (dataSource) => {
|
||||
try {
|
||||
await manager.loadDatabase(
|
||||
await dataSource.sqljsManager.loadDatabase(
|
||||
"test/functional/sqljs/sqlite/test2.sqlite",
|
||||
)
|
||||
expect(true).to.be.false
|
||||
|
||||
@ -2,7 +2,6 @@ import "reflect-metadata"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { expect } from "chai"
|
||||
import { getSqljsManager } from "../../../src/index"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
@ -28,7 +27,7 @@ describe("sqljs driver > save", () => {
|
||||
|
||||
it("should save to file", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
connections.map(async (dataSource) => {
|
||||
if (fs.existsSync(pathToSqlite)) {
|
||||
fs.unlinkSync(pathToSqlite)
|
||||
}
|
||||
@ -36,22 +35,20 @@ describe("sqljs driver > save", () => {
|
||||
let post = new Post()
|
||||
post.title = "The second title"
|
||||
|
||||
const repository = connection.getRepository(Post)
|
||||
const repository = dataSource.getRepository(Post)
|
||||
await repository.save(post)
|
||||
const manager = getSqljsManager("sqljs")
|
||||
|
||||
await manager.saveDatabase(pathToSqlite)
|
||||
await dataSource.sqljsManager.saveDatabase(pathToSqlite)
|
||||
expect(fs.existsSync(pathToSqlite)).to.be.true
|
||||
}),
|
||||
))
|
||||
|
||||
it("should load a file that was saved", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const manager = getSqljsManager("sqljs")
|
||||
await manager.loadDatabase(pathToSqlite)
|
||||
connections.map(async (dataSource) => {
|
||||
await dataSource.sqljsManager.loadDatabase(pathToSqlite)
|
||||
|
||||
const repository = connection.getRepository(Post)
|
||||
const repository = dataSource.getRepository(Post)
|
||||
const post = await repository.findOneBy({
|
||||
title: "The second title",
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user