[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/violetbuse/feather/master/src/feather.gleam [Back]  [Original]

import feather/migrate
import gleam/int
import gleam/option.{type Option, None}
import gleam/result
import sqlight.{type Connection, type Error}

/// Runs the feather cli to generate new migrations and dump the schema
/// you probably don't wanna run this yourself...
/// run `gleam run -m feather` to find out more
pub fn main() {
  migrate.main()
}

pub type JournalMode {
  JournalDelete
  JournalTruncate
  JournalPersist
  JournalMemory
  JournalWal
  JournalOff
}

pub type SyncMode {
  SyncExtra
  SyncFull
  SyncNormal
  SyncOff
}

pub type TempStore {
  TempStoreDefault
  TempStoreFile
  TempStoreMemory
}

pub type Config {
  Config(
    file: String,
    journal_mode: JournalMode,
    synchronous: SyncMode,
    temp_store: TempStore,
    mmap_size: Option(Int),
    page_size: Option(Int),
    foreign_keys: Bool,
  )
}

pub fn default_config() -> Config {
  Config(
    "./sqlite.db",
    journal_mode: JournalWal,
    synchronous: SyncNormal,
    temp_store: TempStoreMemory,
    mmap_size: None,
    page_size: None,
    foreign_keys: True,
  )
}

pub fn connect(config: Config) -> Result(Connection, Error) {
  use connection  "OFF"
    JournalWal -> "WAL"
    JournalDelete -> "DELETE"
    JournalMemory -> "MEMORY"
    JournalTruncate -> "TRUNCATE"
    JournalPersist -> "PERSIST"
  }

  let sync = case config.synchronous {
    SyncOff -> "OFF"
    SyncFull -> "FULL"
    SyncExtra -> "EXTRA"
    SyncNormal -> "NORMAL"
  }

  let temp_store = case config.temp_store {
    TempStoreFile -> "FILE"
    TempStoreMemory -> "MEMORY"
    TempStoreDefault -> "DEFAULT"
  }

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

  use _ 

Web Proxy Viewer  |  New URL  |  Original Page