{"id":20075,"date":"2020-08-18T18:07:31","date_gmt":"2020-08-18T16:07:31","guid":{"rendered":"http:\/\/cornay.co.za\/wp\/?p=20075"},"modified":"2020-08-18T18:07:31","modified_gmt":"2020-08-18T16:07:31","slug":"get-your-sql-statements-right-the-first-time-with-sql-lint","status":"publish","type":"post","link":"http:\/\/cornay.co.za\/wp\/2020\/08\/18\/get-your-sql-statements-right-the-first-time-with-sql-lint\/","title":{"rendered":"Get Your SQL Statements Right the First Time With SQL Lint"},"content":{"rendered":"<p>What&#8217;s your average success rate of getting a SQL statement right on the first try? In best case, you botched a simple statement without side effects and just have to try again with correct syntax or remove that typo from a table name, but things can easily go wrong fast here. But don&#8217;t worry, the days of fixing it on the fly can be over, thanks to [Joe Reynolds] who wrote <a href=\"https:\/\/github.com\/joereynolds\/sql-lint\" target=\"_blank\" rel=\"noopener noreferrer\">a linter for SQL<\/a>.<\/p>\n<p>A linter parses code to tell you where you screwed up. While checking SQL syntax itself is somewhat straightforward, [Joe]&#8217;s <code>sql-lint<\/code> tool will also check the semantics of it by looking up the actual database and performing sanity checks on it. Currently supporting PostgreSQL and MySQL, it can be either run on a single SQL file or a directory of files, or take input directly from the command line. Even better, it also integrates within your editor of choice &#8212; assuming it supports external plugins &#8212; and <a href=\"https:\/\/sql-lint.readthedocs.io\/en\/latest\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">the documentation<\/a> shows how to do that <a href=\"https:\/\/sql-lint.readthedocs.io\/en\/latest\/files\/configuration.html#editor-integration\" target=\"_blank\" rel=\"noopener noreferrer\">specifically for Vim<\/a>.<\/p>\n<p>If you can look past the fact that it&#8217;s written in TypeScript and consequentially results in a rather large executable (<a href=\"https:\/\/github.com\/joereynolds\/sql-lint\/releases\" target=\"_blank\" rel=\"noopener noreferrer\">~40 MB<\/a>), it might serve as an interesting starting point for the language itself, or adds a new perspective on writing <a href=\"https:\/\/hackaday.com\/2018\/12\/12\/warnings-on-steroids-static-code-analysis-tools\/\">this type of analyzer<\/a>. And if databases aren&#8217;t your terrain, <a href=\"https:\/\/hackaday.com\/2017\/03\/29\/lint-for-shell-scripters\/\">how about shell scripts<\/a>?<\/p>\n<p><span id=\"more-427313\"><\/span><\/p>\n<figure id=\"attachment_427316\" aria-describedby=\"caption-attachment-427316\" style=\"width: 960px\" class=\"wp-caption alignright\"><a href=\"http:\/\/cornay.co.za\/wp\/wp-content\/uploads\/2020\/08\/sql-lint-in-action.gif\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" data-attachment-id=\"427316\" data-permalink=\"https:\/\/hackaday.com\/2020\/08\/18\/get-your-sql-statements-right-the-first-time-with-sql-lint\/sql-lint-in-action\/\" data-orig-file=\"http:\/\/cornay.co.za\/wp\/wp-content\/uploads\/2020\/08\/sql-lint-in-action.gif\" data-orig-size=\"960,336\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql-lint-in-action\" data-image-description=\"\" data-medium-file=\"http:\/\/cornay.co.za\/wp\/wp-content\/uploads\/2020\/08\/sql-lint-in-action.gif?w=400\" data-large-file=\"http:\/\/cornay.co.za\/wp\/wp-content\/uploads\/2020\/08\/sql-lint-in-action.gif?w=800\" class=\"wp-image-427316 size-full lazyload\" data-src=\"http:\/\/cornay.co.za\/wp\/wp-content\/uploads\/2020\/08\/sql-lint-in-action.gif\" alt=\"sql-lint in action\" width=\"960\" height=\"336\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 960px; --smush-placeholder-aspect-ratio: 960\/336;\" \/><\/a><figcaption id=\"caption-attachment-427316\" class=\"wp-caption-text\">Example use of sql-lint<\/figcaption><\/figure>\n<p>source <a href=\"https:\/\/hackaday.com\/2020\/08\/18\/get-your-sql-statements-right-the-first-time-with-sql-lint\/\">https:\/\/hackaday.com\/2020\/08\/18\/get-your-sql-statements-right-the-first-time-with-sql-lint\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s your average success rate of getting a SQL statement right on the first try? In best case, you botched a simple statement without side effects and just have to try again with correct syntax or remove that typo from<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"http:\/\/cornay.co.za\/wp\/2020\/08\/18\/get-your-sql-statements-right-the-first-time-with-sql-lint\/\">Read more <span class=\"screen-reader-text\">Get Your SQL Statements Right the First Time With SQL Lint<\/span><span class=\"meta-nav\"> &#8250;<\/span><\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-20075","post","type-post","status-publish","format-standard","hentry","category-news-2"],"_links":{"self":[{"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/posts\/20075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/comments?post=20075"}],"version-history":[{"count":1,"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/posts\/20075\/revisions"}],"predecessor-version":[{"id":20077,"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/posts\/20075\/revisions\/20077"}],"wp:attachment":[{"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/media?parent=20075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/categories?post=20075"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cornay.co.za\/wp\/wp-json\/wp\/v2\/tags?post=20075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}