Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/flowaccount update #2

Merged
merged 18 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ Most tests will benefit from using this template as a starting point:

```ts
import "reflect-metadata";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {expect} from "chai";
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { expect } from "chai";

describe("github issues > #<issue number> <issue title>", () => {

Expand Down
90 changes: 45 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ And more...
With TypeORM your models look like this:

```typescript
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";

@Entity()
export class User {
Expand Down Expand Up @@ -124,7 +124,7 @@ await repository.remove(timber);
Alternatively, if you prefer to use the `ActiveRecord` implementation, you can use it as well:

```typescript
import {Entity, PrimaryGeneratedColumn, Column, BaseEntity} from "typeorm";
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm";

@Entity()
export class User extends BaseEntity {
Expand Down Expand Up @@ -373,7 +373,7 @@ You can load/insert/update/remove and perform other operations with them.
Let's make our `Photo` model as an entity:

```typescript
import {Entity} from "typeorm";
import { Entity } from "typeorm";

@Entity()
export class Photo {
Expand All @@ -396,7 +396,7 @@ To add database columns, you simply need to decorate an entity's properties you
with a `@Column` decorator.

```typescript
import {Entity, Column} from "typeorm";
import { Entity, Column } from "typeorm";

@Entity()
export class Photo {
Expand Down Expand Up @@ -436,7 +436,7 @@ This is a requirement and you can't avoid it.
To make a column a primary key, you need to use `@PrimaryColumn` decorator.

```typescript
import {Entity, Column, PrimaryColumn} from "typeorm";
import { Entity, Column, PrimaryColumn } from "typeorm";

@Entity()
export class Photo {
Expand Down Expand Up @@ -467,7 +467,7 @@ Now, let's say you want your id column to be auto-generated (this is known as au
To do that, you need to change the `@PrimaryColumn` decorator to a `@PrimaryGeneratedColumn` decorator:

```typescript
import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class Photo {
Expand Down Expand Up @@ -500,7 +500,7 @@ We don't want all our columns to be limited varchars or integers.
Let's setup correct data types:

```typescript
import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class Photo {
Expand Down Expand Up @@ -537,8 +537,8 @@ Now, when our entity is created, let's create an `index.ts` (or `app.ts` whateve

```typescript
import "reflect-metadata";
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection({
type: "mysql",
Expand Down Expand Up @@ -574,7 +574,7 @@ Later, when we create more entities we need to add them to the entities in our c
This is not very convenient, so instead we can set up the whole directory, from where all entities will be connected and used in our connection:

```typescript
import {createConnection} from "typeorm";
import { createConnection } from "typeorm";

createConnection({
type: "mysql",
Expand Down Expand Up @@ -622,8 +622,8 @@ Now if you run your `index.ts`, a connection with database will be initialized a
Now let's create a new photo to save it in the database:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(connection => {

Expand Down Expand Up @@ -652,8 +652,8 @@ It's not a new copy of the object, it modifies its "id" and returns it.
Let's take advantage of the latest ES8 (ES2017) features and use async/await syntax instead:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(async connection => {

Expand All @@ -678,8 +678,8 @@ Using entity manager you can manipulate any entity in your app.
For example, let's load our saved entity:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(async connection => {

Expand All @@ -702,8 +702,8 @@ When you deal with entities a lot, Repositories are more convenient to use than


```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(async connection => {

Expand Down Expand Up @@ -732,8 +732,8 @@ Learn more about Repository [here](./docs/working-with-repository.md).
Let's try more load operations using the Repository:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(async connection => {

Expand Down Expand Up @@ -765,8 +765,8 @@ createConnection(/*...*/).then(async connection => {
Now let's load a single photo from the database, update it and save it:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(async connection => {

Expand All @@ -785,8 +785,8 @@ Now photo with `id = 1` will be updated in the database.
Now let's remove our photo from the database:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/).then(async connection => {

Expand All @@ -805,8 +805,8 @@ Let's create a one-to-one relation with another class.
Let's create a new class in `PhotoMetadata.ts`. This PhotoMetadata class is supposed to contain our photo's additional meta-information:

```typescript
import {Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn} from "typeorm";
import {Photo} from "./Photo";
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn } from "typeorm";
import { Photo } from "./Photo";

@Entity()
export class PhotoMetadata {
Expand Down Expand Up @@ -867,9 +867,9 @@ If you run the app, you'll see a newly generated table, and it will contain a co
Now let's save a photo, its metadata and attach them to each other.

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import {PhotoMetadata} from "./entity/PhotoMetadata";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";
import { PhotoMetadata } from "./entity/PhotoMetadata";

createConnection(/*...*/).then(async connection => {

Expand Down Expand Up @@ -915,8 +915,8 @@ To fix this issue we should add an inverse relation, and make relations between
Let's modify our entities:

```typescript
import {Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn} from "typeorm";
import {Photo} from "./Photo";
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn } from "typeorm";
import { Photo } from "./Photo";

@Entity()
export class PhotoMetadata {
Expand All @@ -930,8 +930,8 @@ export class PhotoMetadata {
```

```typescript
import {Entity, Column, PrimaryGeneratedColumn, OneToOne} from "typeorm";
import {PhotoMetadata} from "./PhotoMetadata";
import { Entity, Column, PrimaryGeneratedColumn, OneToOne } from "typeorm";
import { PhotoMetadata } from "./PhotoMetadata";

@Entity()
export class Photo {
Expand Down Expand Up @@ -960,9 +960,9 @@ Let's use `find*` methods first.
`find*` methods allow you to specify an object with the `FindOneOptions` / `FindManyOptions` interface.

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import {PhotoMetadata} from "./entity/PhotoMetadata";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";
import { PhotoMetadata } from "./entity/PhotoMetadata";

createConnection(/*...*/).then(async connection => {

Expand All @@ -980,9 +980,9 @@ Using find options is good and dead simple, but if you need a more complex query
`QueryBuilder` allows more complex queries to be used in an elegant way:

```typescript
import {createConnection} from "typeorm";
import {Photo} from "./entity/Photo";
import {PhotoMetadata} from "./entity/PhotoMetadata";
import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";
import { PhotoMetadata } from "./entity/PhotoMetadata";

createConnection(/*...*/).then(async connection => {

Expand Down Expand Up @@ -1061,8 +1061,8 @@ Let's say a photo has one author, and each author can have many photos.
First, let's create an `Author` class:

```typescript
import {Entity, Column, PrimaryGeneratedColumn, OneToMany, JoinColumn} from "typeorm";
import {Photo} from "./Photo";
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, JoinColumn } from "typeorm";
import { Photo } from "./Photo";

@Entity()
export class Author {
Expand All @@ -1084,9 +1084,9 @@ export class Author {
Now let's add the owner side of the relation into the Photo entity:

```typescript
import {Entity, Column, PrimaryGeneratedColumn, ManyToOne} from "typeorm";
import {PhotoMetadata} from "./PhotoMetadata";
import {Author} from "./Author";
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from "typeorm";
import { PhotoMetadata } from "./PhotoMetadata";
import { Author } from "./Author";

@Entity()
export class Photo {
Expand Down Expand Up @@ -1135,7 +1135,7 @@ Let's say a photo can be in many albums, and each album can contain many photos.
Let's create an `Album` class:

```typescript
import {Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable} from "typeorm";
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from "typeorm";

@Entity()
export class Album {
Expand Down
16 changes: 16 additions & 0 deletions docs/find-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ will execute following query:
SELECT * FROM "post" WHERE "title" LIKE '%out #%'
```

* `ILike`

```ts
import {ILike} from "typeorm";

const loadedPosts = await connection.getRepository(Post).find({
title: ILike("%out #%")
});
```

will execute following query:

```sql
SELECT * FROM "post" WHERE "title" ILIKE '%out #%'
```

* `Between`

```ts
Expand Down
21 changes: 19 additions & 2 deletions docs/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Once you have a migration to run on production, you can run them using a CLI com
typeorm migration:run
```

**`typeorm migration:create` and `typeorm migration:generate` will create `.ts` files. The `migration:run` and `migration:revert` commands only work on `.js` files. Thus the typescript files need to be compiled before running the commands.** Alternatively you can use `ts-node` in conjunction with `typeorm` to run `.ts` migration files.
**`typeorm migration:create` and `typeorm migration:generate` will create `.ts` files, unless you use the `o` flag (see more in [Generating migrations](#generating-migrations)). The `migration:run` and `migration:revert` commands only work on `.js` files. Thus the typescript files need to be compiled before running the commands.** Alternatively you can use `ts-node` in conjunction with `typeorm` to run `.ts` migration files.

Example with `ts-node`:
```
Expand Down Expand Up @@ -194,8 +194,25 @@ export class PostRefactoringTIMESTAMP implements MigrationInterface {
}
```

Alternatively you can also output your migrations as Javascript files using the `o` (alias for `--outputJs`) flag. This is useful for Javascript only projects in which TypeScript additional packages are not installed. This command, will generate a new migration file `{TIMESTAMP}-PostRefactoring.js` with the following content:

```javascript
const { MigrationInterface, QueryRunner } = require("typeorm");

module.exports = class PostRefactoringTIMESTAMP {

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "post" ALTER COLUMN "title" RENAME TO "name"`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "post" ALTER COLUMN "title" RENAME TO "name"`);
}
}
```

See, you don't need to write the queries on your own.
The rule of thumb for generating migrations is that you generate them after "each" change you made to your models. To apply multi-line formatting to your generated migration queries, use the `p` (alias for `--pretty`) flag.
The rule of thumb for generating migrations is that you generate them after **each** change you made to your models. To apply multi-line formatting to your generated migration queries, use the `p` (alias for `--pretty`) flag.

## Connection option
If you need to run/revert your migrations for another connection rather than the default, use the `-c` (alias for `--connection`) and pass the config name as an argument
Expand Down
2 changes: 1 addition & 1 deletion docs/using-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ npm install -g ts-node

Add typeorm command under scripts section in package.json
```
"scripts" {
"scripts": {
...
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
}
Expand Down
16 changes: 16 additions & 0 deletions docs/zh_CN/find-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ const loadedPosts = await connection.getRepository(Post).find({
SELECT * FROM "post" WHERE "title" LIKE '%out #%'
```

- `ILike`

```ts
import { ILike } from "typeorm";

const loadedPosts = await connection.getRepository(Post).find({
title: ILike("%out #%")
});
```

将执行以下查询:

```sql
SELECT * FROM "post" WHERE "title" ILIKE '%out #%'
```

- `Between`

```ts
Expand Down
Loading