#! /bin/env bash FILE=db.sqlite DB=sq://$FILE DEST=./models SCHEMA=0 OPTIND=1 while getopts "s" opt; do case "$opt" in s) SCHEMA=1 esac done popd &> /dev/null mkdir -p $DEST rm -rf $DEST/*.xo.go if [[ "$SCHEMA" = "1" ]]; then echo "Regenerating Schema..." (set -ex; rm $FILE usql -f sql/schema.sql $DB ) fi set -ex xo schema $DB -o $DEST xo schema $DB --template yaml -o $DEST # get all users xo query $DB -M -B -T User -2 -a -F Users -o $DEST << ENDSQL SELECT u.* FROM users u ENDSQL # get user by token xo query $DB -M -B -T User -1 -2 -a -F UserByToken -o $DEST << ENDSQL SELECT u.* FROM tokens t JOIN users u ON t.user_id = u.id WHERE t.token = %%token string%% ENDSQL # delete a specific token xo query $DB -M -B -X -2 -a -F DeleteToken -o $DEST -S token.xo.go << ENDSQL DELETE FROM tokens WHERE token = %%token string%% ENDSQL # delete all tokens for a user xo query $DB -M -B -X -2 -a -F DeleteTokens -o $DEST -S token.xo.go << ENDSQL DELETE FROM tokens WHERE user_id = %%user_id string%% ENDSQL