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

Support for check constraints? #268

Closed
SackCastellon opened this issue Mar 16, 2018 · 0 comments
Closed

Support for check constraints? #268

SackCastellon opened this issue Mar 16, 2018 · 0 comments

Comments

@SackCastellon
Copy link
Contributor

SackCastellon commented Mar 16, 2018

Is there any plan to support check constraints in the future?

Suggestion

Method signature

/**
 * Creates a check constraint in this column
 * @param name The name of the constraint, optional
 * @param op The expression that the value of this column must satisfy
 */
fun <T> Column<T>.check(name: String = "", op: SqlExpressionBuilder.(Column<T>) -> Op<Boolean>): Column<T> { ... }

Usage

object CheckTable : Table("myTable") {
    val id = integer("id").autoIncrement().primaryKey()
    val positive = integer("positive").check { it greaterEq 0 }
    val oneToTen = integer("oneToTen").check("myCheck") { it.between(1, 10) }
    val greaterThanId = integer("greaterThanId").check { it.greater(id) }
}

SQLite Output

CREATE TABLE IF NOT EXISTS myTable (
  id INTEGER PRIMARY KEY,
  positive INT NOT NULL CHECK (positive >= 0),
  oneToTen INT NOT NULL CONSTRAINT myCheck CHECK (oneToTen BETWEEN 1 AND 10),
  greaterThanId INT NOT NULL CHECK (greaterThanId > id)
);
@SackCastellon SackCastellon changed the title Support for "check constraints"? Support for check constraints? Mar 16, 2018
Tapac pushed a commit that referenced this issue Mar 28, 2018
* #268 Add support for check constraints.
* Add support for multi-column check constraints
* Fixed error when parsing check constraints
* Improved CHECK constraint support
- Warning shown when trying to create a CHECK constraint in MySQL
- Constraint with names that were already added are ignored and a warning is shown
- White spaces are now trimmed from constraint names
- Improved tests
* Replaced exception with warn log when using on an unsupported database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant