#+SETUPFILE: ../../../template/level-2.org
#+TITLE: SQL Scripting Best Practices
#+DATE: <2020-04-22 Wed 17:59>
#+AUTHOR: vaeringjar
#+EMAIL: vaeringjar@land
#+DESCRIPTION: SQL Scripting Best Practices
#+KEYWORDS: shell bash

* About

WIP

I plan on copying or referring to this file for best practices. I
admit I might break my own rules and if so, that's a bug!

* Checklist

- Use the 80 column rule and strive for 70.
- End file with a newline.
- Keywords et al should use uppercase.
- delete-trailing-whitespace
- untabify
- Avoid trailing comments
- Prefer -- comments over /*comments*/

* Example checks

#+BEGIN_SRC bash
theFile=path/to/file
grep -Iirn '^.\{71\}' ${theFile}
tail -c 1 ${theFile}
grep -Iirn '/\*\|\*/' ${theFile}
#+END_SRC

#+BEGIN_SRC bash
theFile=path/to/file
sqlformat \
\
--comma_first True\
--indent_columns \
--indent_width 4 \
--wrap_after 70 \
-k upper \
\
-o foo.sql \
\
${theFile}
#+END_SRC

* War stories

- 

* See also

- [[file:shell-scripting-best-practices.org][UNIX-like Shell Scripting Best Practices]]
- https://unix.stackexchange.com/questions/42898/find-any-lines-exceeding-a-certain-length
- https://stackoverflow.com/questions/4631068/how-do-i-find-files-that-do-not-end-with-a-newline-linefeed#20687956
- https://github.com/andialbrecht/sqlparse
