question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column with CHECK Constraint

See original GitHub issue

Is there a support in TypeORM for check contraints? Something like price numeric CHECK (price > 0)? If not maybe it would be a good idea to add that support? It could look like this:

@Column()
@Constraint('price > 0')
price: number;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

25reactions
AlexMessercommented, Mar 20, 2018

Check constraints introduced in typeorm@0.2.0-alpha.29. You can try it via npm i typeorm@next.

Checks work only on table level, e.g.

Entity()
@Check(`"name" IS NOT NULL AND "title" <> 'asd'`)
@Check(`"version" > 0`)
export class Post {

The docs will be updated soon.

5reactions
arnold-almeidacommented, Nov 27, 2018

FYI for those of you who prefer the migration API

const driver = queryRunner.connection.driver
await queryRunner.createCheckConstraint('table', new TableCheck({
  columnNames: ['col'],
  expression: `${driver.escape('col')} > 0`
}))

From: https://github.com/typeorm/typeorm/blob/master/test/functional/query-runner/create-check-constraint.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use SQL Check Constraints - SQLShack
The check constraints are the rule or set of rules that help to check the inserted (or updated) data values to tables based...
Read more >
SQL Server: Check Constraints - TechOnTheNet
The syntax for creating a check constraint in an ALTER TABLE statement in SQL Server (Transact-SQL) is: ALTER TABLE table_name ADD CONSTRAINT constraint_name ......
Read more >
Create Check Constraints - SQL Server - Microsoft Learn
You can create a check constraint in a table to specify the data values that are acceptable in one or more columns in...
Read more >
oracle11g - Add a column to a table with check constraint SQL
I want to add a column to a table, then add a check constraint to make sure its greater than 0. I cant...
Read more >
CHECK Constraint | CockroachDB Docs
The CHECK constraint specifies that values for the column in INSERT or UPDATE statements must return TRUE or NULL for a Boolean expression....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found