<commit_before>-----------------------------------------------------------
-- |
-- Module      :  Database
-- Copyright   :  <NAME> (c) 1999, <EMAIL>
--                HWT Group (c) 2003, <EMAIL>
-- License     :  BSD-style
-- 
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Defines standard database operations and the
-- primitive hooks that a particular database binding
-- must provide.
--
-----------------------------------------------------------
module Database.HaskellDB.Database ( 
		-- * Operators
	      	(!.)
		-- * Type declarations
		, Row(..)
		, Database(..)
		, GetRec(..), GetInstances(..)

		-- * Function declarations
		, query, lazyQuery, strictQuery
		, insert, delete, update, insertQuery
		, tables, describe, transaction
		, createDB, createTable, dropDB, dropTable
		) where

import Database.HaskellDB.HDBRec
import Database.HaskellDB.FieldType
import Database.HaskellDB.PrimQuery
import Database.HaskellDB.Optimize (optimize)
import Database.HaskellDB.Query	
import Database.HaskellDB.BoundedString
import Database.HaskellDB.BoundedList

import System.Time
import Control.Monad

infix 9 !. 

-- | The type of query results.
newtype Row r = Row r

instance ShowRecRow r => ShowRecRow (Row r) where
    showRecRow (Row r) = showRecRow r


-- | The (!.) operator selects over returned records from
--   the database (= rows)
--   Non-overloaded version of '!'. For backwards compatibility.
(!.) :: SelectField f r a => Row r -> Attr f a -> a
(Row row) !. attr = selectAttr attr row

-- | '!' overloaded for selection of fields in query results.
instance SelectField f r a => Select (Row r) (Attr f a) a where
    (Row row) ! attr = selectAttr attr row

-- | Select a field from a record that uses 'Attr' labels.
selectAttr :: SelectField f r a => Attr f a -> r -> a
selectAttr (_::Attr f a) r = selectField (undefined::f) r

data Database
	= Database  
	  { dbQuery  :: forall er vr. GetRec er vr => 
	     PrimQuery 
	     -> Rel er
	     -> IO [vr]
  	  , dbInsert :: TableName -> Assoc -> IO ()
	  , dbInsertQuery :: TableName -> PrimQuery -> IO ()
  	  , dbDelete :: TableName -> [PrimExpr] -> IO ()<commit_msg>change implementation of !. to use !, change ! to use selectField directly<commit_after>-----------------------------------------------------------
-- |
-- Module      :  Database
-- Copyright   :  <NAME> (c) 1999, <EMAIL>
--                HWT Group (c) 2003, <EMAIL>
-- License     :  BSD-style
-- 
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Defines standard database operations and the
-- primitive hooks that a particular database binding
-- must provide.
--
-----------------------------------------------------------
module Database.HaskellDB.Database ( 
		-- * Operators
	      	(!.)
		-- * Type declarations
		, Row(..)
		, Database(..)
		, GetRec(..), GetInstances(..)

		-- * Function declarations
		, query, lazyQuery, strictQuery
		, insert, delete, update, insertQuery
		, tables, describe, transaction
		, createDB, createTable, dropDB, dropTable
		) where

import Database.HaskellDB.HDBRec
import Database.HaskellDB.FieldType
import Database.HaskellDB.PrimQuery
import Database.HaskellDB.Optimize (optimize)
import Database.HaskellDB.Query	
import Database.HaskellDB.BoundedString
import Database.HaskellDB.BoundedList

import System.Time
import Control.Monad

infix 9 !. 

-- | The type of query results.
newtype Row r = Row r

instance ShowRecRow r => ShowRecRow (Row r) where
    showRecRow (Row r) = showRecRow r


-- | The (!.) operator selects over returned records from
--   the database (= rows)
--   Non-overloaded version of '!'. For backwards compatibility.
(!.) :: SelectField f r a => Row r -> Attr f a -> a
row !. attr = row!attr

-- | '!' overloaded for selection of fields in query results.
instance SelectField f r a => Select (Row r) (Attr f a) a where
    (Row r) ! (_::Attr f a) = selectField (undefined::f) r

data Database
	= Database  
	  { dbQuery  :: forall er vr. GetRec er vr => 
	     PrimQuery 
	     -> Rel er
	     -> IO [vr]
  	  , dbInsert :: TableName -> Assoc -> IO ()
	  , dbInsertQuery :: TableName -> PrimQuery -> IO ()
  	  , dbDelete :: TableName -> [PrimExpr] -> IO ()
{'fraction_non_alphanumeric': 0.17339277334584702, 'fraction_numerical': 0.004223369310183012, 'mean_word_length': 2.3046511627906976, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '801461', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1246, 'n_words': 418}