Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DellCliff/frege-dbc
https://github.com/DellCliff/frege-dbc
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/DellCliff/frege-dbc
- Owner: DellCliff
- Created: 2015-09-03T20:47:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-03T20:50:08.000Z (over 9 years ago)
- Last Synced: 2024-02-13T04:39:02.604Z (10 months ago)
- Language: Frege
- Size: 113 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-frege - frege-dbc - JDBC with Frege. (Libraries / Databases)
README
# frege-dbc
This library aims to supply useful functions to deal with JDBC in Frege.
The only function right now is to retrieve results from ResultSet.
fetchRow does not throw exceptions, almost all native JDBC might though, so use with care.```
module Main whereimport frege_dbc.JDBC
import frege_dbc.FregeDBCdrop_table_sql = "DROP TABLE IF EXISTS people"
create_table_sql = "CREATE TABLE people (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, dob TEXT NOT NULL);"
insert_sql = "INSERT INTO people (name, dob) VALUES (\"user 1\", \"2015-08-22T05:31:54\"), (\"user 2\", \"1955-01-10T05:31:54\"), (\"user 3\", \"1985-03-7T05:31:54\");"
query_people_sql = "SELECT * FROM people;"
instance Show SqlValue where
show (SqlString s) = "String: " ++ s
show (SqlInt s) = "Int: " ++ show s
show (SqlLong s) = "Long: " ++ show s
show t = "Some value"main = do
println "START"
conn <- DriverManager.getConnection "jdbc:sqlite:sample.db"
stmt <- Connection.createStatement conndrop_res <- Statement.execute stmt drop_table_sql
create_res <- Statement.execute stmt create_table_sql
insert_res <- Statement.execute stmt insert_sql
-- true if the first result is a ResultSet object;
-- false if the first result is an update count or there is no result
print "drop_res: "; println drop_res
print "create_res: "; println create_res
print "insert_res: "; println insert_respeople_res <- Statement.executeQuery stmt query_people_sql
parsed <- sequence $ [fetchRow people_res | x <- [0..3]] -- more than existprintln parsed
println "END"
```
Prints
```
START
drop_res: false
create_res: false
insert_res: false
[Right [Long: 1, String: user 1, String: 2015-08-22T05:31:54], Right [Long: 2, String: user 2, String: 1955-01-10T05:31:54], Right [Long: 3, String: user 3, String: 1985-03-7T05:31:54], Left java.lang.IllegalStateException: SQLite JDBC: inconsistent internal state]
END
runtime 0.612 wallclock seconds.
```