Hop til hovedindhold

Constraints

Data types are a way to limit the kind of data that can be stored in a table. For many applications, however, the constraint they provide is too coarse. For example, a column containing a product price should probably only accept positive values. But there is no standard data type that accepts only positive numbers. Another issue is that you might want to constrain column data with respect to other columns or rows. For example, in a table containing product information, there should be only one row for each product number.

Get constraint

You can either get a single constraint or a collection of constraints.

All constraints for a table
GET https://api.centia.io/api/v4/schemas/myschema/tables/mytable/constraints HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
Specific constraints by name
GET https://api.centia.io/api/v4/schemas/myschema/tables/mytable/constraints/my-unique-constraint  HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123

An index object looks like this.

{
"name": "my-unique-constraint",
"constraint": "unique",
"columns": ["id"]
}

Add constraint

A constraint can be of either type primary|unique|foreign|check.

Create a unique constraint on one column
POST https://api.centia.io/api/v4/schemas/myschema/tables/mytable/constraints HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123

{
"name": "my-unique-constraint",
"constraint": "unique",
"columns": ["id"]
}

Delete constraint

Delete constraint by name
DELETE https://api.centia.io/api/v4/schemas/myschema/tables/mytable/constraints/my-unique-constraint HTTP/1.1