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

add support for SQLite strict tables #493

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backend/table_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub trait TableBuilder: IndexBuilder + ForeignKeyBuilder + QuotedBuilder + Table
TableOpt::Engine(s) => format!("ENGINE={}", s),
TableOpt::Collate(s) => format!("COLLATE={}", s),
TableOpt::CharacterSet(s) => format!("DEFAULT CHARSET={}", s),
TableOpt::Strict => "STRICT".to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @evgeniy-terekhin, sorry for the delay.

Since STRICT is a SQLite only keyword, we better append it on SQLite's table_builder instead of doing it in the common table_builder.

}
)
.unwrap()
Expand Down
7 changes: 7 additions & 0 deletions src/table/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub enum TableOpt {
Engine(String),
Collate(String),
CharacterSet(String),
Strict,
}

/// All available table partition options
Expand Down Expand Up @@ -246,6 +247,12 @@ impl TableCreateStatement {
self
}

/// Mark table as strict. SQLite only.
pub fn strict(&mut self) -> &mut Self {
self.opt(TableOpt::Strict);
self
}

fn opt(&mut self, option: TableOpt) -> &mut Self {
self.options.push(option);
self
Expand Down
19 changes: 19 additions & 0 deletions tests/sqlite/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,25 @@ fn create_with_unique_index_constraint() {
);
}

#[test]
fn create_strict() {
assert_eq!(
Table::create()
.table(Task::Table)
.col(ColumnDef::new(Task::Id).integer())
.col(ColumnDef::new(Task::IsDone).boolean())
.strict()
.to_string(SqliteQueryBuilder),
[
r#"CREATE TABLE "task" ("#,
r#""id" integer,"#,
r#""is_done" boolean"#,
r#") STRICT"#,
]
.join(" ")
);
}

#[test]
fn drop_1() {
assert_eq!(
Expand Down