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.
Files changed (2) hide show
  1. package/README.md +161 -197
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -20,9 +20,9 @@
20
20
 
21
21
  <!-- toc stop -->
22
22
 
23
- ## Supported databases
23
+ ## Tested databases
24
24
 
25
- Currently tested databases and versions:
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
- Model, Table, Column, DataType, Index, ForeignKey, HasOne
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
- tableName: "person",
481
- timestamps: false,
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
- @Column({
487
- field: "person_id",
488
- primaryKey: true,
489
- type: DataType.INTEGER
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
- @Column({
500
- field: "name",
501
- type: DataType.STRING(80)
502
- })
503
- name!: string;
497
+ @Column({
498
+ type: DataType.STRING(80)
499
+ })
500
+ name!: string;
504
501
 
505
- @Column({
506
- field: "passport_id",
507
- type: DataType.INTEGER
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
- @HasOne(() => passport)
518
- passport?: passport;
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
- Model, Table, Column, DataType, Index, ForeignKey, BelongsTo
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
- tableName: "passport",
531
- timestamps: false,
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
- @ForeignKey(() => person)
537
- @Column({
538
- field: "passport_id",
539
- primaryKey: true,
540
- type: DataType.INTEGER
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
- @Column({
551
- field: "code",
552
- type: DataType.STRING(80)
553
- })
554
- code!: string;
539
+ @Column({
540
+ type: DataType.STRING(80)
541
+ })
542
+ code!: string;
555
543
 
556
- @BelongsTo(() => person)
557
- person?: person;
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
- Model, Table, Column, DataType, Index, ForeignKey, HasMany
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
- tableName: "races",
615
- timestamps: false,
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
- @Column({
621
- field: "race_id",
622
- primaryKey: true,
623
- type: DataType.INTEGER
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
- @Column({
634
- field: "race_name",
635
- type: DataType.STRING(80)
636
- })
637
- race_name!: string;
618
+ @Column({
619
+ type: DataType.STRING(80)
620
+ })
621
+ race_name!: string;
638
622
 
639
- @HasMany(() => units)
640
- units?: units[];
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
- Model, Table, Column, DataType, Index, ForeignKey, BelongsTo
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
- tableName: "units",
653
- timestamps: false,
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
- @Column({
659
- field: "unit_id",
660
- primaryKey: true,
661
- type: DataType.INTEGER
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
- @Column({
672
- field: "unit_name",
673
- type: DataType.STRING(80)
674
- })
675
- unit_name!: string;
655
+ @Column({
656
+ type: DataType.STRING(80)
657
+ })
658
+ unit_name!: string;
676
659
 
677
- @ForeignKey(() => races)
678
- @Column({
679
- field: "race_id",
680
- type: DataType.INTEGER
681
- })
682
- race_id!: number;
660
+ @ForeignKey(() => races)
661
+ @Column({
662
+ type: DataType.INTEGER
663
+ })
664
+ race_id!: number;
683
665
 
684
- @BelongsTo(() => races)
685
- race?: races;
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
- Model, Table, Column, DataType, Index, ForeignKey, BelongsToMany
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
- tableName: "authors",
751
- timestamps: false,
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
- @Column({
757
- field: "author_id",
758
- primaryKey: true,
759
- type: DataType.INTEGER
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
- @Column({
770
- field: "full_name",
771
- type: DataType.STRING(80)
772
- })
773
- full_name!: string;
748
+ @Column({
749
+ type: DataType.STRING(80)
750
+ })
751
+ full_name!: string;
774
752
 
775
- @BelongsToMany(() => books, () => authors_books)
776
- books?: books[];
753
+ @BelongsToMany(() => books, () => authors_books)
754
+ books?: books[];
777
755
 
778
756
  }
779
757
  ```
780
758
 
781
759
  ```ts
782
760
  import {
783
- Model, Table, Column, DataType, Index, ForeignKey, BelongsToMany
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
- tableName: "books",
790
- timestamps: false,
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
- @Column({
796
- field: "book_id",
797
- primaryKey: true,
798
- type: DataType.INTEGER
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
- @Column({
809
- field: "title",
810
- type: DataType.STRING(80)
811
- })
812
- title!: string;
783
+ @Column({
784
+ type: DataType.STRING(80)
785
+ })
786
+ title!: string;
813
787
 
814
- @BelongsToMany(() => authors, () => authors_books)
815
- authors?: authors[];
788
+ @BelongsToMany(() => authors, () => authors_books)
789
+ authors?: authors[];
816
790
 
817
791
  }
818
792
  ```
819
793
 
820
794
  ```ts
821
795
  import {
822
- Model, Table, Column, DataType, Index, ForeignKey
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
- tableName: "authors_books",
829
- timestamps: false,
830
- comment: ""
807
+ tableName: "authors_books",
808
+ timestamps: false
831
809
  })
832
- export class authors_books extends Model {
833
-
834
- @ForeignKey(() => authors)
835
- @Column({
836
- field: "author_id",
837
- primaryKey: true,
838
- type: DataType.INTEGER
839
- })
840
- @Index({
841
- name: "PRIMARY",
842
- using: "BTREE",
843
- order: "ASC",
844
- unique: true
845
- })
846
- author_id!: number;
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.1",
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",