Skip to content

liminalisht/oracle-simple

 
 

Repository files navigation

oracle-simple

Modern bindings to Oracle odpic C library.

  • See here for a list of all structs and functions used in this library.

Example

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
module Main where

import Data.Text (Text)
import Database.Oracle.Simple
import GHC.Generics (Generic)

main :: IO ()
main = do
  let stmt = "select count(*), sysdate, 'ignore next column', 125.24, 3.14 from dual"
  conn <- createConn (ConnectionParams "username" "password" "localhost/XEPDB1")
  rows <- query @ReturnedRow conn stmt
  print rows

-- [ ReturnedRow { count = RowCount {getRowCount = 1.0}
--               , sysdate = DPITimeStamp {year = 2023, month = 9, day = 15, hour = 2, minute = 10, second = 50, fsecond = 0, tzHourOffset = 0, tzMinuteOffset = 0}
--               , hint = "ignore next column"
--               , amount = 125.24000000000001
--               , piValue = 3.14
--               }
-- ]

newtype RowCount = RowCount { getRowCount :: Double }
  deriving (Show)

instance FromField RowCount where
  fromField = RowCount <$> fromField

data ReturnedRow = ReturnedRow
  { count :: RowCount
  , sysdate :: DPITimeStamp
  , hint :: Text
  , amount :: Double
  , piValue :: Double
  }
  deriving stock (Show, Generic)
  deriving anyclass FromRow

-- instance FromRow ReturnedRow where
--   fromRow = do
--     count <- field
--     sysdate <- field
--     amount <- field
--     pure ReturnedRow{..}

Build

$ nix-build
$ nix-shell --run 'cabal build'
$ stack build

Test

$ docker-compose up
$ nix-build && ./result/bin/example

About

Modern bindings to Oracle odpic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 95.3%
  • Nix 3.7%
  • C 1.0%