fixed tslint issues and monogdb issue

This commit is contained in:
Umed Khudoiberdiev 2017-08-01 17:30:13 +05:00
parent e96d7ed0f4
commit 2f037e3af7
10 changed files with 28 additions and 59 deletions

View File

@ -175,36 +175,6 @@ export class Photo {
}
```
### 创建自增长/自生成/顺序化的列
如果你想创建自增长/自生成/顺序化的列需要把column的type改成integer并且给主键列加上一个属性`{ generated: true }`
```typescript
import {Entity, Column, PrimaryColumn} from "typeorm";
@Entity()
export class Photo {
@PrimaryColumn("int", { generated: true })
id: number;
@Column()
name: string;
@Column()
description: string;
@Column()
filename: string;
@Column()
views: number;
@Column()
isPublished: boolean;
}
```
### 使用 `@PrimaryGeneratedColumn` 装饰器
现在photo表的id可能自动生成自动增长不过还是有点麻烦这个一个很常见的功能所以有一个专门的装饰器`@PrimaryGeneratedColumn`来实现相同的功能。

View File

@ -9,7 +9,7 @@ import {PrimaryColumn} from "../../../src/decorator/columns/PrimaryColumn";
@DiscriminatorColumn({ name: "type", type: "varchar" })
export abstract class Person {
@PrimaryColumn("int"/*, { generated: true }*/)
@PrimaryColumn("int")
id: number;
@Column()

View File

@ -13,7 +13,6 @@ export function ObjectIdColumn(options?: ColumnOptions): Function {
if (!options) options = {} as ColumnOptions;
options = Object.assign(options, {
primary: true,
generated: true,
name: options.name ? options.name : "_id"
});

View File

@ -29,7 +29,6 @@ export function PrimaryGeneratedColumn(strategy: "uuid", options?: PrimaryGenera
* Column decorator is used to mark a specific class property as a table column.
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
* This column creates an integer PRIMARY COLUMN with generated set to true.
* This column creates is an alias for @PrimaryColumn("int", { generated: true }).
*/
export function PrimaryGeneratedColumn(strategyOrOptions?: "increment"|"uuid"|PrimaryGeneratedColumnNumericOptions|PrimaryGeneratedColumnUUIDOptions,
maybeOptions?: PrimaryGeneratedColumnNumericOptions|PrimaryGeneratedColumnUUIDOptions): Function {

View File

@ -230,13 +230,6 @@ export interface MongoConnectionOptions extends BaseConnectionOptions {
*/
readonly maxStalenessSeconds?: number;
/**
* The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this
* value in the server log upon establishing each connection. It is also recorded in the slow query log and
* profile collections.
*/
readonly appname?: string;
/**
* Specify the log level used by the driver logger (error/warn/info/debug).
*/

View File

@ -139,7 +139,6 @@ export class MongoDriver implements Driver {
promiseLibrary: this.options.promiseLibrary,
readConcern: this.options.readConcern,
maxStalenessSeconds: this.options.maxStalenessSeconds,
appname: this.options.appname,
loggerLevel: this.options.loggerLevel,
logger: this.options.logger
}, (err: any, dbConnection: any) => {

View File

@ -349,7 +349,7 @@ export class EntityMetadataBuilder {
entityMetadata.columns = entityMetadata.embeddeds.reduce((columns, embedded) => columns.concat(embedded.columnsFromTree), entityMetadata.ownColumns);
entityMetadata.primaryColumns = entityMetadata.columns.filter(column => column.isPrimary);
entityMetadata.hasMultiplePrimaryKeys = entityMetadata.primaryColumns.length > 1;
entityMetadata.generatedColumns = entityMetadata.columns.filter(column => column.isGenerated);
entityMetadata.generatedColumns = entityMetadata.columns.filter(column => column.isGenerated || column.isObjectId);
entityMetadata.createDateColumn = entityMetadata.columns.find(column => column.isCreateDate);
entityMetadata.updateDateColumn = entityMetadata.columns.find(column => column.isUpdateDate);
entityMetadata.versionColumn = entityMetadata.columns.find(column => column.isVersion);

View File

@ -960,16 +960,15 @@ export class SubjectOperationExecutor {
// if (subject.generatedObjectId && subject.metadata.objectIdColumn)
// subject.metadata.objectIdColumn.setEntityValue(subject.entity, subject.generatedObjectId);
subject.metadata.generatedColumns.forEach(generatedColumn => {
if (!subject.generatedMap)
return;
if (subject.generatedMap) {
subject.metadata.generatedColumns.forEach(generatedColumn => {
const generatedValue = generatedColumn.getEntityValue(subject.generatedMap!);
if (!generatedValue)
return;
const generatedValue = generatedColumn.getEntityValue(subject.generatedMap);
if (!generatedValue)
return;
generatedColumn.setEntityValue(subject.entity, generatedValue);
});
generatedColumn.setEntityValue(subject.entity, generatedValue);
});
}
subject.metadata.primaryColumns.forEach(primaryColumn => {
if (subject.parentGeneratedId)
primaryColumn.setEntityValue(subject.entity, subject.parentGeneratedId);

View File

@ -2,12 +2,22 @@ import {Entity} from "../../../../src/decorator/entity/Entity";
import {PrimaryColumn} from "../../../../src/decorator/columns/PrimaryColumn";
import {Column} from "../../../../src/decorator/columns/Column";
@Entity('devices')
@Entity("devices")
export class Device {
@PrimaryColumn({ name: 'id', type: 'char', length: '12' })
@PrimaryColumn({
name: "id",
type: "char",
length: "12"
})
id: string;
@Column({ name: 'registration_token', type: 'decimal', precision: 6, scale: 0 })
@Column({
name: "registration_token",
type: "decimal",
precision: 6,
scale: 0
})
registrationToken: string;
}

View File

@ -5,19 +5,19 @@ import {JoinColumn} from "../../../../src/decorator/relations/JoinColumn";
import {Column} from "../../../../src/decorator/columns/Column";
import {Device} from "./Device";
@Entity('device_instances')
@Entity("device_instances")
export class DeviceInstance {
@PrimaryColumn({ name: 'id', type: 'char', length: '36' })
@PrimaryColumn({ name: "id", type: "char", length: "36" })
id: string;
@ManyToOne(type => Device, { nullable: false })
@JoinColumn({ name: 'device_id', referencedColumnName: 'id' })
@JoinColumn({ name: "device_id", referencedColumnName: "id" })
device: Device;
@Column({ name: 'instance', type: 'smallint' })
@Column({ name: "instance", type: "smallint" })
instance: number;
@Column({ name: 'type', type: 'varchar', length: '30' })
@Column({ name: "type", type: "varchar", length: "30" })
type: string;
}