No description
c38814d7a1
I believe data should be validated at each level of the stack: - database - server - client The database, in my opinion, is the most important layer at which to validate because you can eliminate entire classes of bugs. However, the CHECK constraint is limited, and the more complex the predicates are, the more expensive database operations become. At the server and client layers, the data validations can be more sophisticated and return more useful error messages to help users better understand the shape of the data that our application expects. |
||
---|---|---|
data | ||
src | ||
.gitignore | ||
README.md | ||
shell.nix | ||
todo.org |
TopTal take-home #2
All of the commands defined herein should be run from the top-level directory of this repository (i.e. the directory in which this file exists).
Server
To create the environment that contains all of this application's dependencies, run:
$ nix-shell
To run the server interactively, run:
$ cd src/
$ ghci
Now compile and load the server with:
Prelude> :l Main.hs
*Main> main
Database
Create a new database named db.sqlite3
with:
$ sqlite3 db.sqlite3
Initialize the schema with:
sqlite> .read src/init.sql
You can verify that you successfully initialized the database by running:
sqlite> .tables
sqlite> .schema Accounts
sqlite> .schema Trips
Populate the database with some dummy values using the following:
sqlite> PRAGMA foreign_keys = on;
sqlite> .mode csv
sqlite> .import data/accounts.csv Accounts
sqlite> .import data/trips.csv Trips
You can verify you successfully populated the tables with:
sqlite> .mode columns
sqlite> .headers on
sqlite> SELECT * FROM Accounts;
sqlite> SELECT * FROM Trips;