forked from xo/xo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
executable file
·72 lines (50 loc) · 1.36 KB
/
gen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e
EXTRA=$1
SRC=$(realpath $(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))
XOBIN=$(which xo)
if [ -e $SRC/../../xo ]; then
XOBIN=$SRC/../../xo
fi
XO_ORACLE=$($XOBIN --has-oracle-support)
USQL_ORACLE=$(usql --has-oracle-support)
pushd $SRC &> /dev/null
for i in */config; do
i=$(dirname $i)
# skip
if [ -f $i/skip ]; then
continue
fi
# skip oracle if no oracle support
if [[ $i == "oracle" && ( "$XO_ORACLE" != "1" || "$USQL_ORACLE" != "1" ) ]]; then
continue
fi
source $i/config
MODELS=$i/models
OUT=booktest-$i
mkdir -p $MODELS
rm -f $OUT $MODELS/*.xo.go
echo -e "------------------------------------------------------\n$i='$DB'"
if [ -f $i/pre ]; then
echo -e "\nsourcing $i/pre"
source $i/pre
fi
echo -e "\nusql $DB -f $i/schema.sql"
usql $EXTRA "$DB" -f $i/schema.sql
echo -e "\nxo $DB -o $MODELS"
$XOBIN $EXTRA "$DB" -o $MODELS
echo -e "\nxo $DB -o $MODELS < $i/custom-query.xo.sql"
$XOBIN $EXTRA \
-o $MODELS \
-N -M -B -T AuthorBookResult \
--query-type-comment='AuthorBookResult is the result of a search.' \
"$DB" < $i/custom-query.xo.sql
echo -e "\ngo build -o $OUT ./$i/"
go build -o $OUT ./$i/
echo -e "\n./$OUT"
./$OUT $EXTRA -url "$DB"
echo -e "\nselect * from books;"
usql $EXTRA "$DB" -c 'select * from books;'
echo ""
done
popd &> /dev/null