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

column option unique sqlite error #3803

Closed
chiaraperino opened this issue Mar 11, 2019 · 1 comment
Closed

column option unique sqlite error #3803

chiaraperino opened this issue Mar 11, 2019 · 1 comment
Assignees

Comments

@chiaraperino
Copy link

Issue type:

[x] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.12

Steps to reproduce or a small repository showing the problem:

I have this schema:

export default new EntitySchema({
  tableName: 'vat',
  target: Vat,
  columns: {
    id: { type: 'integer', primary: true, generated: true },
    name: { type: 'varchar', length: 32, unique: true },
    rate: { type: 'integer' },
    notes: { type: 'text', nullable: true },
  },
  checks: [
    { name: 'rate_gt_0', expression: '"rate" > 0' },
  ],
});

but the result query is without unique in name column:

CREATE TABLE "vat" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(32) NOT NULL, "rate" integer NOT NULL, "notes" text, CONSTRAINT "rate_gt_0" CHECK ("rate" > 0))

what's the error in my schema declaration?

Thanks

@vlapo
Copy link
Contributor

vlapo commented Mar 12, 2019

@pleerock is this behaviour by design (wrong typings) or it is bug and unique option on column should works? I think it should works.

@chiaraperino From documentation you can define indices and uniques by separate options:

export const PersonSchema = new EntitySchema({
    // ...
    columns: {
        // ...
    },
    checks: [
        // ...
    ],
    indices: [
        {
            name: "IDX_TEST",
            unique: true,
            columns: [
                "firstName",
                "lastName"
            ]
        }
    ],
    uniques: [
        {
            name: "UNIQUE_TEST",
            columns: [
                "firstName",
                "lastName"
            ]
        }
    ]
});

@AlexMesser AlexMesser self-assigned this Mar 13, 2019
AlexMesser added a commit that referenced this issue Mar 18, 2019
pleerock pushed a commit that referenced this issue Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants