sequelize-typescript-generator 11.0.1 → 11.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -197
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
<!-- toc stop -->
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Tested databases
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
This library is tested on the following databases:
|
|
26
26
|
|
|
27
27
|
- Postgres (11, 14, 16)
|
|
28
28
|
- Mysql (5, 8)
|
|
@@ -472,89 +472,77 @@ This will generate the following models:
|
|
|
472
472
|
|
|
473
473
|
```ts
|
|
474
474
|
import {
|
|
475
|
-
|
|
475
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey, HasOne
|
|
476
476
|
} from "sequelize-typescript";
|
|
477
477
|
import { passport } from "./passport";
|
|
478
478
|
|
|
479
|
+
export interface personAttributes {
|
|
480
|
+
person_id: number;
|
|
481
|
+
name: string;
|
|
482
|
+
passport_id: number;
|
|
483
|
+
}
|
|
484
|
+
|
|
479
485
|
@Table({
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
comment: ""
|
|
486
|
+
tableName: "person",
|
|
487
|
+
timestamps: false
|
|
483
488
|
})
|
|
484
|
-
export class person extends Model {
|
|
489
|
+
export class person extends Model<personAttributes, personAttributes> implements personAttributes {
|
|
485
490
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
@Index({
|
|
492
|
-
name: "PRIMARY",
|
|
493
|
-
using: "BTREE",
|
|
494
|
-
order: "ASC",
|
|
495
|
-
unique: true
|
|
496
|
-
})
|
|
497
|
-
person_id!: number;
|
|
491
|
+
@Column({
|
|
492
|
+
primaryKey: true,
|
|
493
|
+
type: DataType.INTEGER
|
|
494
|
+
})
|
|
495
|
+
person_id!: number;
|
|
498
496
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
name!: string;
|
|
497
|
+
@Column({
|
|
498
|
+
type: DataType.STRING(80)
|
|
499
|
+
})
|
|
500
|
+
name!: string;
|
|
504
501
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
@Index({
|
|
510
|
-
name: "person_passport_passport_id_fk",
|
|
511
|
-
using: "BTREE",
|
|
512
|
-
order: "ASC",
|
|
513
|
-
unique: false
|
|
514
|
-
})
|
|
515
|
-
passport_id!: number;
|
|
502
|
+
@Column({
|
|
503
|
+
type: DataType.INTEGER
|
|
504
|
+
})
|
|
505
|
+
passport_id!: number;
|
|
516
506
|
|
|
517
|
-
|
|
518
|
-
|
|
507
|
+
@HasOne(() => passport, {
|
|
508
|
+
sourceKey: "passport_id"
|
|
509
|
+
})
|
|
510
|
+
passport?: passport;
|
|
519
511
|
|
|
520
512
|
}
|
|
521
513
|
```
|
|
522
514
|
|
|
523
515
|
```ts
|
|
524
516
|
import {
|
|
525
|
-
|
|
517
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey, BelongsTo
|
|
526
518
|
} from "sequelize-typescript";
|
|
527
519
|
import { person } from "./person";
|
|
528
520
|
|
|
521
|
+
export interface passportAttributes {
|
|
522
|
+
passport_id: number;
|
|
523
|
+
code: string;
|
|
524
|
+
}
|
|
525
|
+
|
|
529
526
|
@Table({
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
comment: ""
|
|
527
|
+
tableName: "passport",
|
|
528
|
+
timestamps: false
|
|
533
529
|
})
|
|
534
|
-
export class passport extends Model {
|
|
530
|
+
export class passport extends Model<passportAttributes, passportAttributes> implements passportAttributes {
|
|
535
531
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
@Index({
|
|
543
|
-
name: "PRIMARY",
|
|
544
|
-
using: "BTREE",
|
|
545
|
-
order: "ASC",
|
|
546
|
-
unique: true
|
|
547
|
-
})
|
|
548
|
-
passport_id!: number;
|
|
532
|
+
@ForeignKey(() => person)
|
|
533
|
+
@Column({
|
|
534
|
+
primaryKey: true,
|
|
535
|
+
type: DataType.INTEGER
|
|
536
|
+
})
|
|
537
|
+
passport_id!: number;
|
|
549
538
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
code!: string;
|
|
539
|
+
@Column({
|
|
540
|
+
type: DataType.STRING(80)
|
|
541
|
+
})
|
|
542
|
+
code!: string;
|
|
555
543
|
|
|
556
|
-
|
|
557
|
-
|
|
544
|
+
@BelongsTo(() => person)
|
|
545
|
+
person?: person;
|
|
558
546
|
|
|
559
547
|
}
|
|
560
548
|
```
|
|
@@ -606,83 +594,77 @@ This will generate the following models:
|
|
|
606
594
|
|
|
607
595
|
```ts
|
|
608
596
|
import {
|
|
609
|
-
|
|
597
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey, HasMany
|
|
610
598
|
} from "sequelize-typescript";
|
|
611
599
|
import { units } from "./units";
|
|
612
600
|
|
|
601
|
+
export interface racesAttributes {
|
|
602
|
+
race_id: number;
|
|
603
|
+
race_name: string;
|
|
604
|
+
}
|
|
605
|
+
|
|
613
606
|
@Table({
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
comment: ""
|
|
607
|
+
tableName: "races",
|
|
608
|
+
timestamps: false
|
|
617
609
|
})
|
|
618
|
-
export class races extends Model {
|
|
610
|
+
export class races extends Model<racesAttributes, racesAttributes> implements racesAttributes {
|
|
619
611
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
@Index({
|
|
626
|
-
name: "PRIMARY",
|
|
627
|
-
using: "BTREE",
|
|
628
|
-
order: "ASC",
|
|
629
|
-
unique: true
|
|
630
|
-
})
|
|
631
|
-
race_id!: number;
|
|
612
|
+
@Column({
|
|
613
|
+
primaryKey: true,
|
|
614
|
+
type: DataType.INTEGER
|
|
615
|
+
})
|
|
616
|
+
race_id!: number;
|
|
632
617
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
race_name!: string;
|
|
618
|
+
@Column({
|
|
619
|
+
type: DataType.STRING(80)
|
|
620
|
+
})
|
|
621
|
+
race_name!: string;
|
|
638
622
|
|
|
639
|
-
|
|
640
|
-
|
|
623
|
+
@HasMany(() => units, {
|
|
624
|
+
sourceKey: "race_id"
|
|
625
|
+
})
|
|
626
|
+
units?: units[];
|
|
641
627
|
|
|
642
628
|
}
|
|
643
629
|
```
|
|
644
630
|
|
|
645
631
|
```ts
|
|
646
632
|
import {
|
|
647
|
-
|
|
633
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey, BelongsTo
|
|
648
634
|
} from "sequelize-typescript";
|
|
649
635
|
import { races } from "./races";
|
|
650
636
|
|
|
637
|
+
export interface unitsAttributes {
|
|
638
|
+
unit_id: number;
|
|
639
|
+
unit_name: string;
|
|
640
|
+
race_id: number;
|
|
641
|
+
}
|
|
642
|
+
|
|
651
643
|
@Table({
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
comment: ""
|
|
644
|
+
tableName: "units",
|
|
645
|
+
timestamps: false
|
|
655
646
|
})
|
|
656
|
-
export class units extends Model {
|
|
647
|
+
export class units extends Model<unitsAttributes, unitsAttributes> implements unitsAttributes {
|
|
657
648
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
@Index({
|
|
664
|
-
name: "PRIMARY",
|
|
665
|
-
using: "BTREE",
|
|
666
|
-
order: "ASC",
|
|
667
|
-
unique: true
|
|
668
|
-
})
|
|
669
|
-
unit_id!: number;
|
|
649
|
+
@Column({
|
|
650
|
+
primaryKey: true,
|
|
651
|
+
type: DataType.INTEGER
|
|
652
|
+
})
|
|
653
|
+
unit_id!: number;
|
|
670
654
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
unit_name!: string;
|
|
655
|
+
@Column({
|
|
656
|
+
type: DataType.STRING(80)
|
|
657
|
+
})
|
|
658
|
+
unit_name!: string;
|
|
676
659
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
race_id!: number;
|
|
660
|
+
@ForeignKey(() => races)
|
|
661
|
+
@Column({
|
|
662
|
+
type: DataType.INTEGER
|
|
663
|
+
})
|
|
664
|
+
race_id!: number;
|
|
683
665
|
|
|
684
|
-
|
|
685
|
-
|
|
666
|
+
@BelongsTo(() => races)
|
|
667
|
+
race?: races;
|
|
686
668
|
|
|
687
669
|
}
|
|
688
670
|
```
|
|
@@ -741,123 +723,105 @@ This will generate the following models:
|
|
|
741
723
|
|
|
742
724
|
```ts
|
|
743
725
|
import {
|
|
744
|
-
|
|
726
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey, BelongsToMany
|
|
745
727
|
} from "sequelize-typescript";
|
|
746
728
|
import { books } from "./books";
|
|
747
729
|
import { authors_books } from "./authors_books";
|
|
748
730
|
|
|
731
|
+
export interface authorsAttributes {
|
|
732
|
+
author_id: number;
|
|
733
|
+
full_name: string;
|
|
734
|
+
}
|
|
735
|
+
|
|
749
736
|
@Table({
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
comment: ""
|
|
737
|
+
tableName: "authors",
|
|
738
|
+
timestamps: false
|
|
753
739
|
})
|
|
754
|
-
export class authors extends Model {
|
|
740
|
+
export class authors extends Model<authorsAttributes, authorsAttributes> implements authorsAttributes {
|
|
755
741
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
@Index({
|
|
762
|
-
name: "PRIMARY",
|
|
763
|
-
using: "BTREE",
|
|
764
|
-
order: "ASC",
|
|
765
|
-
unique: true
|
|
766
|
-
})
|
|
767
|
-
author_id!: number;
|
|
742
|
+
@Column({
|
|
743
|
+
primaryKey: true,
|
|
744
|
+
type: DataType.INTEGER
|
|
745
|
+
})
|
|
746
|
+
author_id!: number;
|
|
768
747
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
full_name!: string;
|
|
748
|
+
@Column({
|
|
749
|
+
type: DataType.STRING(80)
|
|
750
|
+
})
|
|
751
|
+
full_name!: string;
|
|
774
752
|
|
|
775
|
-
|
|
776
|
-
|
|
753
|
+
@BelongsToMany(() => books, () => authors_books)
|
|
754
|
+
books?: books[];
|
|
777
755
|
|
|
778
756
|
}
|
|
779
757
|
```
|
|
780
758
|
|
|
781
759
|
```ts
|
|
782
760
|
import {
|
|
783
|
-
|
|
761
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey, BelongsToMany
|
|
784
762
|
} from "sequelize-typescript";
|
|
785
763
|
import { authors } from "./authors";
|
|
786
764
|
import { authors_books } from "./authors_books";
|
|
787
765
|
|
|
766
|
+
export interface booksAttributes {
|
|
767
|
+
book_id: number;
|
|
768
|
+
title: string;
|
|
769
|
+
}
|
|
770
|
+
|
|
788
771
|
@Table({
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
comment: ""
|
|
772
|
+
tableName: "books",
|
|
773
|
+
timestamps: false
|
|
792
774
|
})
|
|
793
|
-
export class books extends Model {
|
|
775
|
+
export class books extends Model<booksAttributes, booksAttributes> implements booksAttributes {
|
|
794
776
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
@Index({
|
|
801
|
-
name: "PRIMARY",
|
|
802
|
-
using: "BTREE",
|
|
803
|
-
order: "ASC",
|
|
804
|
-
unique: true
|
|
805
|
-
})
|
|
806
|
-
book_id!: number;
|
|
777
|
+
@Column({
|
|
778
|
+
primaryKey: true,
|
|
779
|
+
type: DataType.INTEGER
|
|
780
|
+
})
|
|
781
|
+
book_id!: number;
|
|
807
782
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
title!: string;
|
|
783
|
+
@Column({
|
|
784
|
+
type: DataType.STRING(80)
|
|
785
|
+
})
|
|
786
|
+
title!: string;
|
|
813
787
|
|
|
814
|
-
|
|
815
|
-
|
|
788
|
+
@BelongsToMany(() => authors, () => authors_books)
|
|
789
|
+
authors?: authors[];
|
|
816
790
|
|
|
817
791
|
}
|
|
818
792
|
```
|
|
819
793
|
|
|
820
794
|
```ts
|
|
821
795
|
import {
|
|
822
|
-
|
|
796
|
+
Model, Table, Column, DataType, Index, Sequelize, ForeignKey
|
|
823
797
|
} from "sequelize-typescript";
|
|
824
798
|
import { authors } from "./authors";
|
|
825
799
|
import { books } from "./books";
|
|
826
800
|
|
|
801
|
+
export interface authors_booksAttributes {
|
|
802
|
+
author_id: number;
|
|
803
|
+
book_id: number;
|
|
804
|
+
}
|
|
805
|
+
|
|
827
806
|
@Table({
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
comment: ""
|
|
807
|
+
tableName: "authors_books",
|
|
808
|
+
timestamps: false
|
|
831
809
|
})
|
|
832
|
-
export class authors_books extends Model {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
@ForeignKey(() => books)
|
|
849
|
-
@Column({
|
|
850
|
-
field: "book_id",
|
|
851
|
-
primaryKey: true,
|
|
852
|
-
type: DataType.INTEGER
|
|
853
|
-
})
|
|
854
|
-
@Index({
|
|
855
|
-
name: "PRIMARY",
|
|
856
|
-
using: "BTREE",
|
|
857
|
-
order: "ASC",
|
|
858
|
-
unique: true
|
|
859
|
-
})
|
|
860
|
-
book_id!: number;
|
|
810
|
+
export class authors_books extends Model<authors_booksAttributes, authors_booksAttributes> implements authors_booksAttributes {
|
|
811
|
+
|
|
812
|
+
@ForeignKey(() => authors)
|
|
813
|
+
@Column({
|
|
814
|
+
primaryKey: true,
|
|
815
|
+
type: DataType.INTEGER
|
|
816
|
+
})
|
|
817
|
+
author_id!: number;
|
|
818
|
+
|
|
819
|
+
@ForeignKey(() => books)
|
|
820
|
+
@Column({
|
|
821
|
+
primaryKey: true,
|
|
822
|
+
type: DataType.INTEGER
|
|
823
|
+
})
|
|
824
|
+
book_id!: number;
|
|
861
825
|
|
|
862
826
|
}
|
|
863
827
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sequelize-typescript-generator",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.2",
|
|
4
4
|
"description": "Automatically generates typescript models compatible with sequelize-typescript library (https://www.npmjs.com/package/sequelize-typescript) directly from your source database.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|