| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Database
Description
Synopsis
- sampleCommands :: IO Integer
- data Column = Column {}
- newColumn :: String -> Datatype -> [String] -> Maybe Column
- data Table = Table {}
- newTable :: String -> ([String], Map String Column) -> [Int] -> Maybe Table
- data Database = Database {}
- newDatabase :: String -> Map String Table -> Maybe Database
- data Datatype
- containsTable :: String -> Maybe Database -> Bool
- containsColumn :: String -> Maybe Database -> String -> Bool
- getTable :: String -> Maybe Database -> Maybe Table
- count :: Maybe Table -> Int
- getColumn :: String -> Maybe Table -> Maybe Column
- addNewTable :: String -> Maybe Database -> Maybe Database
- addColumnToTable :: String -> Datatype -> Table -> Table
- addColumn :: String -> Datatype -> Maybe Database -> String -> Maybe Database
- insertOne :: String -> Datatype -> Maybe Database -> String -> String -> Maybe Database
- isValidDatatype :: Maybe Table -> [String] -> [Datatype] -> Bool
- addPrimaryKeyToTable :: Table -> Table
- addPrimaryKey :: Maybe Database -> String -> Maybe Database
- insert :: [String] -> [String] -> [Datatype] -> Maybe Database -> String -> Maybe Database
- insertDefault :: [String] -> Maybe Database -> String -> Maybe Database
- getColList :: String -> Maybe Database -> [Column]
- findEntryAtIndex :: String -> Maybe Database -> Int -> [(Int, String, Datatype, String)]
- litValue :: String -> Datatype -> ValueExpr
- find :: Either ParseError ValueExpr -> Maybe Database -> String -> [[(Int, String, Datatype, String)]]
- deleteFromList :: Int -> [a] -> [a]
- deleteEntryAtIndex :: Int -> Maybe Database -> String -> Maybe Database
- deleteEntryAtIndices :: [Int] -> Maybe Database -> String -> Maybe Database
- delete :: Either ParseError ValueExpr -> Maybe Database -> String -> Maybe Database
- orderBy :: Either ParseError ValueExpr -> [[(Int, String, Datatype, String)]] -> [[(Int, String, Datatype, String)]]
- select :: [(String, String)] -> [[(Int, String, Datatype, String)]] -> [[(Int, String, Datatype, String)]]
Documentation
sampleCommands :: IO Integer Source #
sampleCommands is for debugging purposes.
Column stores a column in a table as a list of its values along with the datatype and name of column
newColumn :: String -> Datatype -> [String] -> Maybe Column Source #
newColumn Returns new column (Maybe Column)
First argument is name of column
Second argument is datatype
Third argument is list of values
Table stores a map of columns (key is column Name) with table name and list of names of columns
Constructors
| Table | |
newTable :: String -> ([String], Map String Column) -> [Int] -> Maybe Table Source #
newTable returns new table (Maybe Table)
First argument is table name
Second argument is (list of colNames, Map of those colnames -> Columns)
Database stores a database with a name and map of tables indexed by their names
newDatabase :: String -> Map String Table -> Maybe Database Source #
newDatabase returns new database (Maybe Database)
First argument is datbase name
Second argument map of tables indexed by their names
Datatype is for datatype in a column
containsTable :: String -> Maybe Database -> Bool Source #
containsTable is True if database contains table, o/w False
First argument is tableName
Second argument is database object (Maybe database)
containsColumn :: String -> Maybe Database -> String -> Bool Source #
containsColumn returns True if table within database contains a column, o/w false
First argument is column name
Second argument is database (Maybe Database)
Third argument is table name
getTable :: String -> Maybe Database -> Maybe Table Source #
getTable returns table from database (Maybe Table)
First argument is table name
Second argument is database (Maybe Database)
count :: Maybe Table -> Int Source #
count returns the number of entries in a table
First argument is table (Maybe Table)
getColumn :: String -> Maybe Table -> Maybe Column Source #
getColumn returns column in specific table of a database (Maybe Column)
First argument is name of column (String)
Second argument is table (Maybe Table)
addNewTable :: String -> Maybe Database -> Maybe Database Source #
addNewTable adds an empty table to database and returns new database (Maybe Database)
First argument is tableName (String)
Second argument is database (Maybe Database)
addColumnToTable :: String -> Datatype -> Table -> Table Source #
addColumnToTable adds a column to a table and returns new table (Table)
First argument is column name (String)
Second argument is column datatype (Datatype)
Third argumenr is old table (Table)
addColumn :: String -> Datatype -> Maybe Database -> String -> Maybe Database Source #
addColumn adds a column to specific table in database and returns new database (Maybe Database)
First argument is column name (String)
Second argumenr is column datatype (Datatype)
Third argumenr is database (Maybe Database)
Fourth argumenr is table name (String)
insertOne :: String -> Datatype -> Maybe Database -> String -> String -> Maybe Database Source #
insertOne inserts one entry in one column of one table in a database
First argument is value (String)
Second argument is it's datatype (Datatype)
Third argument is old database (Maybe Database)
Fourth argument is table name (String)
Fifth argumenr is column name (String)
isValidDatatype :: Maybe Table -> [String] -> [Datatype] -> Bool Source #
isValidDatatype checks if datatypes corresponding to column names list are in sync with the table in database or not. Returns true if they both conform
First argumenr is table (Maybe Table)
Second argument is list of column names [String]
Third argument is list of datatypes [Datatype]
addPrimaryKeyToTable :: Table -> Table Source #
addPrimaryKeyToTable adds one primary key to a table
First argument is a table (Table)
addPrimaryKey :: Maybe Database -> String -> Maybe Database Source #
addPrimaryKey adds one primary key to table in database
First argument is database (Maybe Database)
Second argument is table name (String)
insert :: [String] -> [String] -> [Datatype] -> Maybe Database -> String -> Maybe Database Source #
insert inserts an entry (row) in database -> table and returns new database
First argumenr is list of colNames [String]
Second argument is corresponding list of values [String]
Third argumenr is corresponding list of datatypes [Datatype]
Fourth argument old database (Maybe Database)
Fifth argument is table name (String)
insertDefault :: [String] -> Maybe Database -> String -> Maybe Database Source #
insertDefault inserts an entry in the default column order. This does not check for datatype as of now.
First argument is list of values
Second argument is old database
Third argument is tableName
getColList :: String -> Maybe Database -> [Column] Source #
getColList is a Utility function for find*
findEntryAtIndex :: String -> Maybe Database -> Int -> [(Int, String, Datatype, String)] Source #
findEntryAtIndex finds entry at index in table and returns as [tuples] where tuple = (col name, col type, col value)
First argument is tableName
Second argument is database
Third argument is index
litValue :: String -> Datatype -> ValueExpr Source #
litValue is a utility function to support evaluation of ValueExpr on columns (which are stored as String)
find :: Either ParseError ValueExpr -> Maybe Database -> String -> [[(Int, String, Datatype, String)]] Source #
find finds all entries in (db -> table) with value, datype and returns as [entries] where entry=[tuples] where tuple = (col name, col type, col value)
First argument is value (Right) ValueExpr that evaluates to true or false
Second argument is database (Maybe Database)
Third argument is table name
deleteFromList :: Int -> [a] -> [a] Source #
deleteFromList is a utility function to delete an entry from a list
deleteEntryAtIndex :: Int -> Maybe Database -> String -> Maybe Database Source #
deleteEntryAtIndex deletes an entry from the table
First argument is the index in table for the entry to be deleted
Second argument is the database (Maybe Database)
Third argument is table name
deleteEntryAtIndices :: [Int] -> Maybe Database -> String -> Maybe Database Source #
deleteEntryAtIndices is used to delete multiple entries from a specific table of a database
First argument is list of indices [Int]
Second argument is database (Maybe Database)
Third argumenr is table name (String)
delete :: Either ParseError ValueExpr -> Maybe Database -> String -> Maybe Database Source #
delete deletes all entries that follow a specific condition from a table
First argument is condition
Second argument is Maybe Database
Third argument is table name (String)
orderBy :: Either ParseError ValueExpr -> [[(Int, String, Datatype, String)]] -> [[(Int, String, Datatype, String)]] Source #
orderBy orders the entries given by find based on the value given by expression
First argument is the expression that gives the deciding value
Second argument is the entrylist returned by find / select
select :: [(String, String)] -> [[(Int, String, Datatype, String)]] -> [[(Int, String, Datatype, String)]] Source #
select selects specific columns from the output of find/orderBy and returns list of entries with those columns only
First argument is column alias (if new name of the columns is needed, then this is used). If this is empty, all columns with default names are returned
Second argument is output of find/orderBy