Skip to content

Commit

Permalink
remove globals usages
Browse files Browse the repository at this point in the history
  • Loading branch information
pleerock committed Apr 2, 2022
1 parent 9d1e246 commit 2205a1a
Show file tree
Hide file tree
Showing 33 changed files with 198 additions and 165 deletions.
9 changes: 5 additions & 4 deletions sample/sample1-simple-entity/app.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions sample/sample10-mixed/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions sample/sample11-all-types-entity/app.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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"
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions sample/sample12-custom-naming-strategy/app.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions sample/sample13-everywhere-abstraction/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions sample/sample14-errors-in-wrong-metdata/app.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"

Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions sample/sample16-indexes/app.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions sample/sample17-versioning/app.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions sample/sample18-lazy-relations/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
15 changes: 8 additions & 7 deletions sample/sample19-one-side-relations/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions sample/sample2-one-to-one/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions sample/sample20-join-without-relation/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions sample/sample21-custom-join-table-column/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions sample/sample22-closure-table/app.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions sample/sample23-nested-joins/app.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
Loading

0 comments on commit 2205a1a

Please sign in to comment.