newtype Query a
= Query String
data Connection :: *
data DB :: !
type ConnectionString = String
type ConnectionInfo = { password :: String, user :: String, port :: Number, db :: String, host :: String }
mkConnectionString :: ConnectionInfo -> ConnectionString
connect :: forall eff. ConnectionInfo -> Aff (db :: DB | eff) Connection
Makes a connection to the database.
execute :: forall eff a. Query a -> [SqlValue] -> Connection -> Aff (db :: DB | eff) Unit
Runs a query and returns nothing.
execute_ :: forall eff a. Query a -> Connection -> Aff (db :: DB | eff) Unit
Runs a query and returns nothing
query :: forall eff a. (IsForeign a) => Query a -> [SqlValue] -> Connection -> Aff (db :: DB | eff) [F a]
Runs a query and returns all results.
query_ :: forall eff a. (IsForeign a) => Query a -> Connection -> Aff (db :: DB | eff) [a]
Just like query
but does not make any param replacement
queryOne :: forall eff a. (IsForeign a) => Query a -> [SqlValue] -> Connection -> Aff (db :: DB | eff) (Maybe a)
Runs a query and returns the first row, if any
queryOne_ :: forall eff a. (IsForeign a) => Query a -> Connection -> Aff (db :: DB | eff) (Maybe a)
Just like queryOne
but does not make any param replacement
queryValue :: forall eff a. (IsForeign a) => Query a -> [SqlValue] -> Connection -> Aff (db :: DB | eff) (Maybe a)
Runs a query and returns a single value, if any.
queryValue_ :: forall eff a. (IsForeign a) => Query a -> Connection -> Aff (db :: DB | eff) (Maybe a)
Just like queryValue
but does not make any param replacement
withConnection :: forall eff a. ConnectionInfo -> (Connection -> Aff (db :: DB | eff) a) -> Aff (db :: DB | eff) a
Connects to the database, calls the provided function with the connection and returns the results.
close :: forall eff. Connection -> Eff (db :: DB | eff) Unit
data Pool :: *
createPool :: forall eff. ConnectionInfo -> Eff (db :: DB | eff) Pool
Create a connection pool.
createPoolFromString :: forall eff. ConnectionString -> Eff (db :: DB | eff) Pool
Create a connection pool. Remember to call closePool
.
closePool :: forall eff. Pool -> Eff (db :: DB | eff) Unit
Close the connection pool.
withPool :: forall eff a. Pool -> (Connection -> Aff (db :: DB | eff) a) -> Aff (db :: DB | eff) a
Run a database action with a connection from the specified Pool
.
data SqlValue :: *
class IsSqlValue a where
toSql :: a -> SqlValue
instance isSqlValueString :: IsSqlValue String
instance isSqlValueNumber :: IsSqlValue Number
instance isSqlValueInt :: IsSqlValue Int
instance isSqlValueMaybe :: (IsSqlValue a) => IsSqlValue (Maybe a)
data Transaction :: *
withTransaction :: forall eff a. (Connection -> Aff (db :: DB | eff) a) -> Connection -> Aff (db :: DB | eff) a
finally :: forall e a. Aff e a -> Aff e Unit -> Aff e a
Compute aff1
, followed by aff2
regardless of whether aff1
terminated successfully.