A database connection is an object representing an active communication channel to a database. In Haskell's sqlite-simple, open creates a Connection for a local database file or a temporary :memory: database. section 16.3.1
Use the connection as the first argument to database operations:
- Run SELECT statements with query or query_, which return parsed rows. section 16.3.1
- Run INSERT, UPDATE, and DELETE statements with execute, execute_, executeMany, or executeNamed. section 16.3.1
- Bundle setup and application-specific actions in a database module whose functions receive the Connection. section 16.3.3
- Protect multi-step changes with withTransaction and handle failures with try. section 16.3.3
An in-memory connection
dbConn <- open ":memory:"; execute_ dbConn "CREATE TABLE myTable (id INTEGER PRIMARY KEY, data TEXT)"; execute dbConn "INSERT INTO myTable VALUES (?,?)" (1 :: Int, "hello" :: String); query_ dbConn "SELECT * FROM myTable" returns [(1,"hello")].





