mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
changeed auto_increment to generated
This commit is contained in:
parent
6eae0b5398
commit
c435802678
10
README.md
10
README.md
@ -62,7 +62,7 @@ import {PrimaryColumn, Column} from "typeorm/columns";
|
||||
@Table("photo")
|
||||
export class Photo {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
@ -85,7 +85,7 @@ Here, we are using three decorators:
|
||||
for this class. We also specified a table name in the database.
|
||||
* `@PrimaryColumn(columnType, columnOptions)` - tells ORM to create a table
|
||||
column for the given class property and make it *PRIMARY KEY* column. We also
|
||||
set `{ autoIncrement: true }` in column options, which makes our
|
||||
set `{ generated: true }` in column options, which makes our
|
||||
primary column an *AUTO_INCREMENT*.
|
||||
* `@Column(columnType, columnOptions)` - tells ORM to create a table
|
||||
column for the given class property.
|
||||
@ -224,7 +224,7 @@ import {OneToOne} from "typeorm/relations";
|
||||
@Table("photo_metadata")
|
||||
export class PhotoMetadata {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
@ -426,7 +426,7 @@ import {OneToMany} from "typeorm/relations";
|
||||
@Table("author")
|
||||
export class Author {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
@ -535,7 +535,7 @@ import {ManyToMany} from "typeorm/relations";
|
||||
@Table("album")
|
||||
export class Album {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -85,7 +85,7 @@ ColumnOptions is an object with additional column options:
|
||||
* `type?: ColumnType` - column type also can be specified via column options
|
||||
* `length?: string` - column type's length. For example type = "string" and length = 100 means that ORM will create a
|
||||
column with type varchar(100).
|
||||
* `autoIncrement?: boolean` - specifies if this column will use AUTO_INCREMENT or not (e.g. generated number)
|
||||
* `generated?: boolean` - specifies if this column will use AUTO_INCREMENT or not (e.g. generated number)
|
||||
* `unique?: boolean` - specifies if column's value must be unique or not.
|
||||
* `nullable?: boolean` - indicates if column's value can be set to NULL.
|
||||
* `columnDefinition?: string` - Extra column definition. Should be used only in emergency situations.
|
||||
@ -106,7 +106,7 @@ class Photo {
|
||||
/**
|
||||
* Primary column with auto increment key.
|
||||
*/
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
/**
|
||||
|
||||
@ -25,7 +25,7 @@ must mark your table with `@AbstractTable()` decorator:
|
||||
@AbstractTable()
|
||||
export class BasePhoto {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -4,7 +4,7 @@ import {Table} from "../../../src/tables";
|
||||
@Table("sample1_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -7,7 +7,7 @@ import {PostDetails} from "./PostDetails";
|
||||
@Table("sample10_category")
|
||||
export class Category {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {PostDetails} from "./PostDetails";
|
||||
@Table("sample10_chapter")
|
||||
export class Chapter {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample10_cover")
|
||||
export class Cover {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -7,7 +7,7 @@ import {ImageDetails} from "./ImageDetails";
|
||||
@Table("sample10_image")
|
||||
export class Image {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Image} from "./Image";
|
||||
@Table("sample10_image_details")
|
||||
export class ImageDetails {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -9,7 +9,7 @@ import {PostDetails} from "./PostDetails";
|
||||
@Table("sample10_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column({
|
||||
|
||||
@ -9,7 +9,7 @@ import {OneToOneInverse} from "../../../src/decorator/relations/OneToOneInverse"
|
||||
@Table("sample10_post_details")
|
||||
export class PostDetails {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {UpdateDateColumn} from "../../../src/decorator/columns/UpdateDateColumn"
|
||||
@Table("sample11_everything_entity")
|
||||
export class EverythingEntity {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -4,7 +4,7 @@ import {Table} from "../../../src/tables";
|
||||
@Table("sample1_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -11,7 +11,7 @@ import {PostMetadata} from "./PostMetadata";
|
||||
@Table("sample2_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToOneInverse} from "../../../src/relations";
|
||||
@Table("sample2_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -4,7 +4,7 @@ import {Table} from "../../../src/tables";
|
||||
@Table("sample2_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample2_post_details")
|
||||
export class PostDetails {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToOneInverse} from "../../../src/relations";
|
||||
@Table("sample2_post_image")
|
||||
export class PostImage {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample2_post_information")
|
||||
export class PostInformation {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToOneInverse} from "../../../src/relations";
|
||||
@Table("sample2_post_metadata")
|
||||
export class PostMetadata {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -11,7 +11,7 @@ import {PostMetadata} from "./PostMetadata";
|
||||
@Table("sample3_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToMany} from "../../../src/relations";
|
||||
@Table("sample3_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -4,7 +4,7 @@ import {Table} from "../../../src/tables";
|
||||
@Table("sample3_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample3_post_details")
|
||||
export class PostDetails {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column({
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToMany} from "../../../src/relations";
|
||||
@Table("sample3_post_image")
|
||||
export class PostImage {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample3_post_information")
|
||||
export class PostInformation {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToMany} from "../../../src/relations";
|
||||
@Table("sample3_post_metadata")
|
||||
export class PostMetadata {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -11,7 +11,7 @@ import {PostMetadata} from "./PostMetadata";
|
||||
@Table("sample4_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {ManyToManyInverse} from "../../../src/relations";
|
||||
@Table("sample4_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -4,7 +4,7 @@ import {Table} from "../../../src/tables";
|
||||
@Table("sample4_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample4_post_details")
|
||||
export class PostDetails {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column({
|
||||
|
||||
@ -6,7 +6,7 @@ import {ManyToManyInverse} from "../../../src/relations";
|
||||
@Table("sample4_post_image")
|
||||
export class PostImage {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {Post} from "./Post";
|
||||
@Table("sample4_post_information")
|
||||
export class PostInformation {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {ManyToManyInverse} from "../../../src/relations";
|
||||
@Table("sample4_post_metadata")
|
||||
export class PostMetadata {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -9,7 +9,7 @@ import {ManyToOne} from "../../../src/decorator/relations/ManyToOne";
|
||||
@Table("sample5_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToMany} from "../../../src/decorator/relations/OneToMany";
|
||||
@Table("sample5_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {ManyToManyInverse} from "../../../src/decorator/relations/ManyToManyInve
|
||||
@Table("sample5_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -9,7 +9,7 @@ import {AbstractTable} from "../../../src/decorator/tables/AbstractTable";
|
||||
@AbstractTable()
|
||||
export class BasePost {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToMany} from "../../../src/decorator/relations/OneToMany";
|
||||
@Table("sample6_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {ManyToManyInverse} from "../../../src/decorator/relations/ManyToManyInve
|
||||
@Table("sample6_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -8,7 +8,7 @@ import {ManyToOne} from "../../../src/decorator/relations/ManyToOne";
|
||||
@Table("sample7_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {OneToMany} from "../../../src/decorator/relations/OneToMany";
|
||||
@Table("sample7_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -6,7 +6,7 @@ import {ManyToManyInverse} from "../../../src/decorator/relations/ManyToManyInve
|
||||
@Table("sample7_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -10,7 +10,7 @@ import {OneToOneInverse} from "../../../src/decorator/relations/OneToOneInverse"
|
||||
@Table("sample8_category")
|
||||
export class Category {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -15,7 +15,7 @@ import {AfterRemove} from "../../../src/decorator/listeners/AfterRemove";
|
||||
@Table("sample9_post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -12,7 +12,7 @@ import {BeforeInsert} from "../../../src/decorator/listeners/BeforeInsert";
|
||||
@Table("sample9_post_author")
|
||||
export class PostAuthor {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -12,7 +12,7 @@ import {BeforeInsert} from "../../../src/decorator/listeners/BeforeInsert";
|
||||
@Table("sample9_post_category")
|
||||
export class PostCategory {
|
||||
|
||||
@PrimaryColumn("int", { autoIncrement: true })
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -49,7 +49,7 @@ export function Column(typeOrOptions?: ColumnType|ColumnOptions, options?: Colum
|
||||
throw new ColumnTypeUndefinedError(object, propertyName);
|
||||
|
||||
// check if auto increment is not set for simple column
|
||||
if (options.autoIncrement)
|
||||
if (options.generated)
|
||||
throw new AutoIncrementOnlyForPrimaryError(object, propertyName);
|
||||
|
||||
// create and register a new column metadata
|
||||
|
||||
@ -182,8 +182,8 @@ export class ColumnMetadata extends PropertyMetadata {
|
||||
|
||||
if (args.options.length)
|
||||
this.length = args.options.length;
|
||||
if (args.options.autoIncrement)
|
||||
this.isAutoIncrement = args.options.autoIncrement;
|
||||
if (args.options.generated)
|
||||
this.isAutoIncrement = args.options.generated;
|
||||
if (args.options.unique)
|
||||
this.isUnique = args.options.unique;
|
||||
if (args.options.nullable)
|
||||
|
||||
@ -24,7 +24,7 @@ export interface ColumnOptions {
|
||||
/**
|
||||
* Specifies if this column will use AUTO_INCREMENT or not (e.g. generated number).
|
||||
*/
|
||||
autoIncrement?: boolean;
|
||||
generated?: boolean;
|
||||
|
||||
/**
|
||||
* Specifies if column's value must be unique or not.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user