mirror of
https://github.com/ilyakooo0/IdrisSqlite.git
synced 2024-11-22 23:30:08 +03:00
Type-providers demo all but compiles - cant find implementation Handler Sqlite m
This commit is contained in:
parent
8fec8fc60e
commit
c6b602557a
@ -2,6 +2,8 @@ module ParserHack
|
|||||||
import Schema
|
import Schema
|
||||||
import SQLiteTypes
|
import SQLiteTypes
|
||||||
|
|
||||||
|
%access export
|
||||||
|
|
||||||
people : String
|
people : String
|
||||||
people = "CREATE TABLE \"people\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , \"name\" VARCHAR NOT NULL , \"age\" INTEGER)"
|
people = "CREATE TABLE \"people\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , \"name\" VARCHAR NOT NULL , \"age\" INTEGER)"
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import Queries
|
|||||||
import Schema
|
import Schema
|
||||||
import SQLiteTypes
|
import SQLiteTypes
|
||||||
|
|
||||||
|
%access export
|
||||||
|
|
||||||
%language TypeProviders
|
%language TypeProviders
|
||||||
|
|
||||||
mkDB : ResultSet -> Either String (List (String, Schema))
|
mkDB : ResultSet -> Either String (List (String, Schema))
|
||||||
@ -22,7 +24,7 @@ mkDB ([DBText v]::rest) =
|
|||||||
Right List.(::) <*> Right (t, tbl) <*> mkDB rest
|
Right List.(::) <*> Right (t, tbl) <*> mkDB rest
|
||||||
mkDB _ = Left "Couldn't understand SQLite output - wrong type"
|
mkDB _ = Left "Couldn't understand SQLite output - wrong type"
|
||||||
|
|
||||||
getSchemas : (filename : String) -> { [SQLITE ()] } Eff (Provider (DB filename))
|
getSchemas : (filename : String) -> Eff (Provider (DB filename)) [SQLITE ()]
|
||||||
getSchemas file =
|
getSchemas file =
|
||||||
do let ddlQuery = "SELECT `sql` FROM `sqlite_master` " ++
|
do let ddlQuery = "SELECT `sql` FROM `sqlite_master` " ++
|
||||||
"WHERE NOT (sqlite_master.name LIKE \"sqlite%\");"
|
"WHERE NOT (sqlite_master.name LIKE \"sqlite%\");"
|
||||||
@ -35,24 +37,23 @@ getSchemas file =
|
|||||||
Left err => pure (Error err)
|
Left err => pure (Error err)
|
||||||
Right db => pure (Provide (MkDB file db))
|
Right db => pure (Provide (MkDB file db))
|
||||||
|
|
||||||
getRow : (s : Schema) -> { [SQLITE (SQLiteExecuting ValidRow)] } Eff (Row s)
|
getRow : (s : Schema) -> SimpleEff.Eff (Row s) [SQLITE (SQLiteExecuting ValidRow)]
|
||||||
getRow s = go 0 s
|
getRow s = go 0 s
|
||||||
where go : Int -> (s : Schema) -> { [SQLITE (SQLiteExecuting ValidRow)] } Eff (Row s)
|
where go : Int -> (s : Schema) -> Eff (Row s) [SQLITE (SQLiteExecuting ValidRow)]
|
||||||
go i [] = pure []
|
go i [] = pure []
|
||||||
go i ((_ ::: ty) :: s) = [| getCol ty :: go (i+1) s |]
|
go i ((_ ::: ty) :: s) = [| getCol ty :: go (i+1) s |]
|
||||||
where getCol : (t : SQLiteType) -> { [SQLITE (SQLiteExecuting ValidRow)] } Eff (interpSql t)
|
where getCol : (t : SQLiteType) -> Eff (interpSql t) [SQLITE (SQLiteExecuting ValidRow)]
|
||||||
getCol TEXT = getColumnText i
|
getCol TEXT = getColumnText i
|
||||||
getCol INTEGER = do int <- getColumnInt i
|
getCol INTEGER = do int <- getColumnInt i
|
||||||
pure (cast int)
|
pure (cast int)
|
||||||
getCol REAL = getColumnFloat i
|
getCol REAL = getColumnFloat i
|
||||||
getCol (NULLABLE x) = do nullp <- isColumnNull i
|
getCol (NULLABLE x) = do nullp <- isColumnNull i
|
||||||
if nullp
|
case nullp of
|
||||||
then pure Nothing
|
True => pure Nothing
|
||||||
else do val <- getCol x
|
False => do val <- getCol x
|
||||||
pure (Just val)
|
pure (Just val)
|
||||||
|
|
||||||
collectRows : (s : Schema) -> { [SQLITE (SQLiteExecuting ValidRow)] ==>
|
collectRows : (s : Schema) -> Eff (Table s) [SQLITE (SQLiteExecuting ValidRow)] [SQLITE (SQLiteExecuting InvalidRow)]
|
||||||
[SQLITE (SQLiteExecuting InvalidRow)] } Eff (Table s)
|
|
||||||
collectRows s = do row <- getRow s
|
collectRows s = do row <- getRow s
|
||||||
case !nextRow of
|
case !nextRow of
|
||||||
Unstarted => pure $ row :: !(collectRows s)
|
Unstarted => pure $ row :: !(collectRows s)
|
||||||
@ -60,8 +61,7 @@ collectRows s = do row <- getRow s
|
|||||||
StepComplete => pure $ row :: !(collectRows s)
|
StepComplete => pure $ row :: !(collectRows s)
|
||||||
NoMoreRows => pure [row]
|
NoMoreRows => pure [row]
|
||||||
|
|
||||||
query : {file : String} -> {db : DB file} -> Query db s ->
|
query : {file : String} -> {db : DB file} -> Query db s -> Eff (Either QueryError (Table s)) [SQLITE ()]
|
||||||
{ [SQLITE ()] } Eff (Either QueryError (Table s))
|
|
||||||
query {file=fn} q =
|
query {file=fn} q =
|
||||||
case !(openDB fn) of
|
case !(openDB fn) of
|
||||||
Left err => pure $ Left err
|
Left err => pure $ Left err
|
||||||
|
@ -9,6 +9,7 @@ import Language.Reflection
|
|||||||
import Language.Reflection.Errors
|
import Language.Reflection.Errors
|
||||||
import Language.Reflection.Utils
|
import Language.Reflection.Utils
|
||||||
|
|
||||||
|
%access public export
|
||||||
%default total
|
%default total
|
||||||
%language ErrorReflection
|
%language ErrorReflection
|
||||||
|
|
||||||
@ -106,7 +107,6 @@ namespace Query
|
|||||||
solveHasTable (HasTable ts n s) = reflectListPrf ts `Seq` Solve
|
solveHasTable (HasTable ts n s) = reflectListPrf ts `Seq` Solve
|
||||||
solveHasTable (HasTable (x ++ y) n s) = Solve
|
solveHasTable (HasTable (x ++ y) n s) = Solve
|
||||||
|
|
||||||
|
|
||||||
data Tables : DB file -> Schema -> Type where
|
data Tables : DB file -> Schema -> Type where
|
||||||
T : (name : String) ->
|
T : (name : String) ->
|
||||||
{default tactics { byReflection solveHasTable;}
|
{default tactics { byReflection solveHasTable;}
|
||||||
@ -164,18 +164,9 @@ namespace Query
|
|||||||
where cols : String
|
where cols : String
|
||||||
cols = Foldable.concat . List.intersperse ", " . colNames $ proj
|
cols = Foldable.concat . List.intersperse ", " . colNames $ proj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- -}
|
|
||||||
-- -}
|
|
||||||
-- -}
|
|
||||||
|
|
||||||
---------- Proofs ----------
|
---------- Proofs ----------
|
||||||
Queries.Row.projectRow_lemma : Row s
|
|
||||||
Queries.Row.projectRow_lemma = proof
|
Queries.Row0.projectRow_lemma = proof
|
||||||
intros
|
intros
|
||||||
rewrite (attrEta attr)
|
rewrite (attrEta attr)
|
||||||
exact value
|
exact value
|
||||||
|
@ -8,7 +8,7 @@ import Decidable.Equality
|
|||||||
public export data SQLiteType = TEXT | INTEGER | REAL
|
public export data SQLiteType = TEXT | INTEGER | REAL
|
||||||
| NULLABLE SQLiteType
|
| NULLABLE SQLiteType
|
||||||
|
|
||||||
export interpSql : SQLiteType -> Type
|
public export interpSql : SQLiteType -> Type
|
||||||
interpSql TEXT = String
|
interpSql TEXT = String
|
||||||
interpSql INTEGER = Integer
|
interpSql INTEGER = Integer
|
||||||
interpSql REAL = Double
|
interpSql REAL = Double
|
||||||
|
@ -36,14 +36,11 @@ talks = SELECT ["title":::TEXT, "abstract":::TEXT]
|
|||||||
FROM "talk"
|
FROM "talk"
|
||||||
WHERE 1
|
WHERE 1
|
||||||
|
|
||||||
|
|
||||||
program : Query db ["name":::TEXT, "title":::TEXT, "abstract":::TEXT]
|
program : Query db ["name":::TEXT, "title":::TEXT, "abstract":::TEXT]
|
||||||
program = SELECT ["name":::TEXT, "title":::TEXT, "abstract":::TEXT]
|
program = SELECT ["name":::TEXT, "title":::TEXT, "abstract":::TEXT]
|
||||||
FROM "speaker" * "talk"
|
FROM "speaker" * "talk"
|
||||||
WHERE Col "id" == Col "speaker"
|
WHERE Col "id" == Col "speaker"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printRes : Query db s -> IO ()
|
printRes : Query db s -> IO ()
|
||||||
printRes q = do res <- runInit [()] (query q)
|
printRes q = do res <- runInit [()] (query q)
|
||||||
case res of
|
case res of
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package demo
|
package demo
|
||||||
|
|
||||||
modules = Test, ErrorHandlers, parser, Schema, Database, ErrorTest, Provider, SQLiteTypes, ParserHack, Queries
|
modules = Test, ErrorHandlers, Parser, Schema, Database, ErrorTest, Provider, SQLiteTypes, ParserHack, Queries
|
||||||
|
|
||||||
executable = test
|
executable = test
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user