Skip to content

Instantly share code, notes, and snippets.

@noprompt
Last active December 13, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noprompt/4963866 to your computer and use it in GitHub Desktop.
Save noprompt/4963866 to your computer and use it in GitHub Desktop.
(defmacro SQL* [& clauses]
(let [query (walk/postwalk
(fn [x]
(if (and (symbol? x) (re-find #"^[A-Z]+$" (name x)))
(if (resolve x)
x
(str x))
x)) clauses)
query (cons 'list query)]
`(join \space ~query)))
@noprompt
Copy link
Author

(defn load-data-infile [file table]
  (SQL*
    LOAD DATA INFILE (sql-dquote file)
    IGNORE INTO TABLE (sql-escape table)
    FIELDS TERMINATED BY (sql-dquote "|") LINES TERMINATED BY (sql-dquote "\\n")
    IGNORE 1 LINES))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment