Flake & cabal setup
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Yore.DB
|
||||
( Table (..)
|
||||
, getTables
|
||||
) where
|
||||
|
||||
import Database.PostgreSQL.LibPQ (Connection)
|
||||
import GHC.Generics (Generic)
|
||||
|
||||
import qualified Database.PostgreSQL.Opium as Opium
|
||||
|
||||
data Table = Table
|
||||
{ schema :: String
|
||||
, name :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
instance Opium.FromRow Table
|
||||
|
||||
getTables :: Connection -> IO (Either Opium.Error [Table])
|
||||
getTables = Opium.fetch_ "SELECT table_schema AS schema, table_name AS name FROM information_schema.tables"
|
||||
@@ -0,0 +1,13 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Yore.Repl (connect, exec) where
|
||||
|
||||
import qualified Database.PostgreSQL.LibPQ as LibPQ
|
||||
|
||||
import Database.PostgreSQL.LibPQ (Connection)
|
||||
|
||||
connect :: IO Connection
|
||||
connect = LibPQ.connectdb "host=localhost"
|
||||
|
||||
exec :: (Connection -> IO a) -> IO a
|
||||
exec f = f =<< connect
|
||||
Reference in New Issue
Block a user