From 77ed3f9344a655d6ca6cd410db93fa407f6221a1 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Thu, 15 Aug 2013 23:43:47 +0900 Subject: [PATCH] Add typed delete running sequence. --HG-- rename : relational-query-HDBC/src/Database/HDBC/Record/Insert.hs => relational-query-HDBC/src/Database/HDBC/Record/Delete.hs --- .../relational-query-HDBC.cabal | 1 + .../src/Database/HDBC/Record/Delete.hs | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 relational-query-HDBC/src/Database/HDBC/Record/Delete.hs diff --git a/relational-query-HDBC/relational-query-HDBC.cabal b/relational-query-HDBC/relational-query-HDBC.cabal index 4cb2308f..012b3b5a 100644 --- a/relational-query-HDBC/relational-query-HDBC.cabal +++ b/relational-query-HDBC/relational-query-HDBC.cabal @@ -27,6 +27,7 @@ library Database.HDBC.Record.Statement Database.HDBC.Record.Query Database.HDBC.Record.Insert + Database.HDBC.Record.Delete Database.HDBC.Query.TH Database.HDBC.SqlValueExtra Database.HDBC.Schema.Driver diff --git a/relational-query-HDBC/src/Database/HDBC/Record/Delete.hs b/relational-query-HDBC/src/Database/HDBC/Record/Delete.hs new file mode 100644 index 00000000..4e87cd4e --- /dev/null +++ b/relational-query-HDBC/src/Database/HDBC/Record/Delete.hs @@ -0,0 +1,74 @@ +{-# LANGUAGE FlexibleContexts #-} + +-- | +-- Module : Database.HDBC.Record.Delete +-- Copyright : 2013 Kei Hibino +-- License : BSD3 +-- +-- Maintainer : ex8k.hibino@gmail.com +-- Stability : experimental +-- Portability : unknown +-- +-- This module provides typed 'Delete' running sequence +-- which intermediate structres are typed. +module Database.HDBC.Record.Delete ( + PreparedDelete, prepare, prepareDelete, + BoundDelete, ExecutedDelete, executeDelete, + + runPreparedDelete, runDelete + ) where + +import Database.HDBC (IConnection, SqlValue) + +import Database.Relational.Query (Delete, untypeDelete) +import Database.Record (ToSql) + +import Database.HDBC.Record.Statement + (unsafePrepare, PreparedStatement, + BoundStatement, + executeNoFetch, ExecutedStatement, + runPreparedNoFetch) + + +-- | Typed prepared insert type. +type PreparedDelete p = PreparedStatement p () + +-- | Typed prepared insert which has bound placeholder parameters. +type BoundDelete = BoundStatement () + +-- | Typed executed insert. +type ExecutedDelete = ExecutedStatement () + +-- | Typed prepare insert operation. +prepare :: IConnection conn + => conn + -> Delete p + -> IO (PreparedDelete p) +prepare conn = unsafePrepare conn . untypeDelete + +-- | Same as 'prepare'. +prepareDelete :: IConnection conn + => conn + -> Delete p + -> IO (PreparedDelete p) +prepareDelete = prepare + +-- | Typed execute insert operation. +executeDelete :: BoundDelete -> IO Integer +executeDelete = executeNoFetch + +-- | Bind parameters, execute statement and get execution result. +runPreparedDelete :: ToSql SqlValue p + => p + -> PreparedDelete p + -> IO Integer +runPreparedDelete = runPreparedNoFetch + +-- | Prepare insert statement, bind parameters, +-- execute statement and get execution result. +runDelete :: (IConnection conn, ToSql SqlValue p) + => conn + -> p + -> Delete p + -> IO Integer +runDelete conn p = (>>= runPreparedDelete p) . prepareDelete conn