Table of Contents

1 HDBC-sqlite3

cabal install HDBC-sqlite3 
cabal install sqlite
-- run ghci

-- load module
ghci>:module Database.HDBC Database.HDBC.Sqlite3

-- create connection
ghci>conn <- connectSqlite3 "students.db"
-- check the type of connection 
ghci>:t conn

-- check the function
ghci>:t connectSqlite3

-- create a table
ghci>run conn "CREATE TABLE names (id INTEGER NOT NULL, fname VARCHAR(80), lname VARCHAR(80))" []

-- check the type of signature of run

-- insert data to table
ghci>run conn "INSERT INTO names (id, fname, lname) VALUES(1, 'Edwin', 'Brady')" []

-- commit it
ghci>commit conn

-- query data from table
ghci> quickQuery conn "SELECT * from names" []

-- login to sqlite3 in Command Line if you want to
sqlite3 students.db

2 sqlite-simple

  • Install sqlite-simple.
cabal install sqlite-simple
  • Local file example.
  • Run sqlite from command line with database file.
# from my MacOS
sqlite3  /Users/cat/myfile/bitbucket/testfile/test.db
  • Sqlit console commands, or sqlit3 -help
# quit
# show tables
  • Open connection in Haskell.
conn <- open "test.db"

3 Haskell and Sqlite Commands

  • Empty table
  • Create table
  • Insert data
  • Select data from table

Author: cat

Created: 2019-07-09 Tue 16:58