Created
November 7, 2019 15:46
-
-
Save rwenz3l/be6df7a8bad69cec67527eb9227090da to your computer and use it in GitHub Desktop.
Convert golang `db:"field"` comments into a sql-query for json objects..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
file2jsql(){ | |
# $1=file, $2=table_name | |
keyval=$(cat "${1}" | perl -n -e '/`db:"(.*)"\ / && printf(qq{"%s", %s,\n},$1,$1);') | |
keyval=${keyval%?} | |
echo "SELECT JSON_OBJECT(" | |
echo "$keyval" | |
echo ") FROM ${2};" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment