gdritter repos electric-boogaloo / bddb931
Added ? operator for nullable types Getty Ritter 7 years ago
2 changed file(s) with 19 addition(s) and 9 deletion(s). Collapse all Expand all
2525 null int integer real text blob date
2626 ~~~
2727
28 or the name of a table declared in the source file.
28 or the name of a table declared in the source file. By default
29 all values are given the `NOT NULL` qualifier, but this can be
30 avoided by ending a type name with a `?` operator.
2931
3032 All tables get an implicit `id` column of the form
3133
4749
4850 authors
4951 name: text
50 gender: blob
52 gender: blob?
5153 ~~~
5254
5355 Produces the following SQLite table declarations:
5557 ~~~.sql
5658 CREATE TABLE books
5759 ( id INTEGER PRIMARY KEY ASC
58 , title TEXT
59 , author_name INTEGER
60 , published DATE
60 , title TEXT NOT NULL
61 , author_name INTEGER NOT NULL
62 , published DATE NOT NULL
6163 , FOREIGN KEY(author_name) REFERENCES authors(id)
6264 );
6365 CREATE TABLE authors
6466 ( id INTEGER PRIMARY KEY ASC
65 , name TEXT
67 , name TEXT NOT NULL
6668 , gender BLOB
6769 );
6870 ~~~
1313 data Field = Field
1414 { fName :: Text
1515 , fType :: Text
16 , fNull :: Bool
1617 } deriving (Eq, Show)
1718
1819 uncomment :: Text -> Text
2829 | T.length (T.takeWhile isSpace l) > 0 =
2930 let (n, t) = T.break (== ':') (T.strip l)
3031 f = Field { fName = T.strip n
31 , fType = T.strip (T.drop 1 t)
32 , fType = T.strip (T.drop 1 (T.filter (/= '?') t))
33 , fNull = T.any (== '?') t
3234 }
3335 in case ds of
3436 (d:ds') -> go (d { dFields = f : dFields d } : ds') ls
7577 mapM_ printField fs
7678 mapM_ printForeign fs
7779 T.putStrLn " );"
78 where printField Field { fName = f, fType = t } = do
80 where printField Field { fName = f
81 , fType = t
82 , fNull = l
83 } = do
7984 T.putStr " , "
8085 T.putStr f
8186 T.putStr " "
82 T.putStrLn (typeName t)
87 T.putStr (typeName t)
88 if not l
89 then T.putStrLn " NOT NULL"
90 else T.putStrLn ""
8391 printForeign Field { fName = f, fType = t }
8492 | t `elem` builtins = return ()
8593 | otherwise = do