Skip to content

Commit

Permalink
added support for the foreign _key pragma
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletBuse committed Jul 31, 2024
1 parent c9ed5b9 commit cc3d17b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/feather.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub type Config {
temp_store: TempStore,
mmap_size: Option(Int),
page_size: Option(Int),
foreign_keys: Bool,
)
}

Expand All @@ -52,6 +53,7 @@ pub fn default_config() -> Config {
temp_store: TempStoreMemory,
mmap_size: None,
page_size: None,
foreign_keys: True,
)
}

Expand Down Expand Up @@ -80,6 +82,11 @@ pub fn connect(config: Config) -> Result(Connection, Error) {
TempStoreDefault -> "DEFAULT"
}

let foreign_keys = case config.foreign_keys {
True -> "on"
False -> "off"
}

use _ <- result.try(sqlight.exec(
"PRAGMA journal_mode = " <> journal_mode <> ";",
connection,
Expand Down Expand Up @@ -108,6 +115,11 @@ pub fn connect(config: Config) -> Result(Connection, Error) {
|> option.unwrap(Ok(Nil)),
)

use _ <- result.try(sqlight.exec(
"PRAGMA foreign_keys = " <> foreign_keys <> ";",
connection,
))

Ok(connection)
}

Expand Down

0 comments on commit cc3d17b

Please sign in to comment.