Skip to content

Commit

Permalink
editing dox.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Oct 15, 2020
1 parent 21ecd0a commit ce1ddc3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
27 changes: 23 additions & 4 deletions docs/tech.v3.dataset.sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,29 @@
<ul>
<li><code>:table-name</code> - set the name of the table to use. Overrides the dataset metadata.</li>
<li><code>:primary-key</code> - Array of column names to use as the primary key of this table. Overrides the dataset metadata.</li>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L114">view source</a></div></div><div class="public anchor" id="var-drop-table.21"><h3>drop-table!</h3><div class="usage"><code>(drop-table! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Drop a table. Exception upon failure to drop the table.</p>
<p>conn - java.sql.Connection dataset - string, keyword, symbol, or dataset.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L97">view source</a></div></div><div class="public anchor" id="var-drop-table-when-exists.21"><h3>drop-table-when-exists!</h3><div class="usage"><code>(drop-table-when-exists! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Drop the table indicated by this dataset if it exists.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L107">view source</a></div></div><div class="public anchor" id="var-ensure-table.21"><h3>ensure-table!</h3><div class="usage"><code>(ensure-table! conn dataset options)</code><code>(ensure-table! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Create a table if it does not exist. See documentation for create-table!</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L146">view source</a></div></div><div class="public anchor" id="var-execute-prepared-statement-batches"><h3>execute-prepared-statement-batches</h3><div class="usage"><code>(execute-prepared-statement-batches conn stmt-or-sql dataset options)</code></div><div class="doc"><div class="markdown"></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L159">view source</a></div></div><div class="public anchor" id="var-insert-dataset.21"><h3>insert-dataset!</h3><div class="usage"><code>(insert-dataset! conn dataset options)</code><code>(insert-dataset! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Insert a dataset into a table indicated by the dataset name.</p>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L115">view source</a></div></div><div class="public anchor" id="var-drop-table.21"><h3>drop-table!</h3><div class="usage"><code>(drop-table! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Drop a table. Exception upon failure to drop the table.</p>
<ul>
<li>conn - java.sql.Connection</li>
<li>dataset - string, keyword, symbol, or dataset</li>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L98">view source</a></div></div><div class="public anchor" id="var-drop-table-when-exists.21"><h3>drop-table-when-exists!</h3><div class="usage"><code>(drop-table-when-exists! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Drop the table indicated by this dataset if it exists.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L108">view source</a></div></div><div class="public anchor" id="var-ensure-table.21"><h3>ensure-table!</h3><div class="usage"><code>(ensure-table! conn dataset options)</code><code>(ensure-table! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Create a table if it does not exist. See documentation for create-table!</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L147">view source</a></div></div><div class="public anchor" id="var-execute-prepared-statement-batches"><h3>execute-prepared-statement-batches</h3><div class="usage"><code>(execute-prepared-statement-batches conn stmt-or-sql dataset options)</code></div><div class="doc"><div class="markdown"><p>Internal method to, using a dataset, execute prepared statement batches drawn from the rows of the dataset. For this to work correctly, the connection needs to have autoCommit set to false.</p>
<ul>
<li>conn - java.sql.Connection</li>
<li>stmt-or-sql - Either a prepared statement or a string in which case the connection’s .prepareStatement method will be called.</li>
<li>dataset - dataset</li>
</ul>
<p>Options</p>
<ul>
<li>batch-size - integer, defaults to 32</li>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L160">view source</a></div></div><div class="public anchor" id="var-insert-dataset.21"><h3>insert-dataset!</h3><div class="usage"><code>(insert-dataset! conn dataset options)</code><code>(insert-dataset! conn dataset)</code></div><div class="doc"><div class="markdown"><p>Insert a dataset into a table indicated by the dataset name.</p>
<p>Options:</p>
<ul>
<li><code>:postgres-upsert?</code> - defaults to false. When true, generates postgres-specific sql that performs an upsert operation.</li>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L193">view source</a></div></div><div class="public anchor" id="var-result-set-.3Edataset"><h3>result-set-&gt;dataset</h3><div class="usage"><code>(result-set-&gt;dataset results {:keys [close?], :or {close? true}, :as options})</code><code>(result-set-&gt;dataset results)</code></div><div class="doc"><div class="markdown"><p>Given a result set, return a dataset. options: :close? - if true, then .close is called on the resultset - always - including when there is an exception. Defaults to true.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L19">view source</a></div></div><div class="public anchor" id="var-sanitize-dataset-names-for-sql"><h3>sanitize-dataset-names-for-sql</h3><div class="usage"><code>(sanitize-dataset-names-for-sql ds)</code></div><div class="doc"><div class="markdown"><p>Given a dataset, sanitize the dataset name and the names of all the columns such that they are safe for insert to SQL.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L70">view source</a></div></div><div class="public anchor" id="var-sql-.3Edataset"><h3>sql-&gt;dataset</h3><div class="usage"><code>(sql-&gt;dataset conn sql options)</code><code>(sql-&gt;dataset conn sql)</code></div><div class="doc"><div class="markdown"><p>Given a connection and an sql statement, convert the results of executing the statement to a dataset. For options, see result-set-&gt;dataset</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L54">view source</a></div></div><div class="public anchor" id="var-table-exists.3F"><h3>table-exists?</h3><div class="usage"><code>(table-exists? conn dataset)</code></div><div class="doc"><div class="markdown"><p>Test if a table exists.</p>
<p>conn - java.sql.Connection dataset - string, keyword, symbol, or dataset.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L83">view source</a></div></div></div></body></html>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L207">view source</a></div></div><div class="public anchor" id="var-result-set-.3Edataset"><h3>result-set-&gt;dataset</h3><div class="usage"><code>(result-set-&gt;dataset results {:keys [close?], :or {close? true}, :as options})</code><code>(result-set-&gt;dataset results)</code></div><div class="doc"><div class="markdown"><p>Given a result set, return a dataset.</p>
<p>Options:</p>
<ul>
<li><code>:close?</code> - if true, then .close is called on the resultset - always - including when there is an exception. Defaults to true.</li>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L19">view source</a></div></div><div class="public anchor" id="var-sanitize-dataset-names-for-sql"><h3>sanitize-dataset-names-for-sql</h3><div class="usage"><code>(sanitize-dataset-names-for-sql ds)</code></div><div class="doc"><div class="markdown"><p>Given a dataset, sanitize the dataset name and the names of all the columns such that they are safe for insert to SQL.</p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L71">view source</a></div></div><div class="public anchor" id="var-sql-.3Edataset"><h3>sql-&gt;dataset</h3><div class="usage"><code>(sql-&gt;dataset conn sql options)</code><code>(sql-&gt;dataset conn sql)</code></div><div class="doc"><div class="markdown"><p>Given a connection and an sql statement, convert the results of executing the statement to a dataset. For options, see <code>result-set-&gt;dataset</code></p></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L56">view source</a></div></div><div class="public anchor" id="var-table-exists.3F"><h3>table-exists?</h3><div class="usage"><code>(table-exists? conn dataset)</code></div><div class="doc"><div class="markdown"><p>Test if a table exists.</p>
<ul>
<li>conn - java.sql.Connection</li>
<li>dataset - string, keyword, symbol, or dataset</li>
</ul></div></div><div class="src-link"><a href="https://github.com/techascent/tech.ml.dataset.sql/blob/master/src/tech/v3/dataset/sql.clj#L84">view source</a></div></div></div></body></html>
34 changes: 24 additions & 10 deletions src/tech/v3/dataset/sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

(defn result-set->dataset
"Given a result set, return a dataset.
options:
:close? - if true, then .close is called on the resultset - always - including when
Options:
* `:close?` - if true, then .close is called on the resultset - always - including when
there is an exception. Defaults to true."
([^ResultSet results {:keys [close?]
:or {close? true}
Expand Down Expand Up @@ -53,8 +55,7 @@

(defn sql->dataset
"Given a connection and an sql statement, convert the results of executing the
statement to a dataset.
For options, see result-set->dataset"
statement to a dataset. For options, see `result-set->dataset`"
([^Connection conn sql options]
(try
(with-open [statement (.createStatement conn)]
Expand Down Expand Up @@ -83,8 +84,8 @@
(defn table-exists?
"Test if a table exists.
conn - java.sql.Connection
dataset - string, keyword, symbol, or dataset."
* conn - java.sql.Connection
* dataset - string, keyword, symbol, or dataset"
[conn dataset]
(try
(sql->dataset conn (format "Select COUNT(*) from %s where 1 = 0"
Expand All @@ -97,8 +98,8 @@
(defn drop-table!
"Drop a table. Exception upon failure to drop the table.
conn - java.sql.Connection
dataset - string, keyword, symbol, or dataset."
* conn - java.sql.Connection
* dataset - string, keyword, symbol, or dataset"
[conn dataset]
(sql-impl/execute-update! conn (format "DROP TABLE %s"
(sql-impl/dataset->table-name dataset))))
Expand All @@ -114,7 +115,7 @@
(defn create-table!
"Create a table. Exception upon failure to drop the table.
- conn - java.sql.Connection
- conn - java.sql.Connection
- dataset - dataset to use. The dataset-name will be used as the table-name and the
column names and datatypes will be used for the sql names and datatypes.
Expand Down Expand Up @@ -157,6 +158,19 @@


(defn execute-prepared-statement-batches
"Internal method to, using a dataset, execute prepared statement batches
drawn from the rows of the dataset. For this to work correctly, the
connection needs to have autoCommit set to false.
* conn - java.sql.Connection
* stmt-or-sql - Either a prepared statement or a string in which case
the connection's .prepareStatement method will be called.
* dataset - dataset
Options
- batch-size - integer, defaults to 32
"
[^Connection conn stmt-or-sql dataset options]
(let [n-rows (ds/row-count dataset)
batch-size (long (or (:batch-size options) 32))]
Expand Down Expand Up @@ -193,7 +207,7 @@
(defn insert-dataset!
"Insert a dataset into a table indicated by the dataset name.
Options:
Options:
- `:postgres-upsert?` - defaults to false. When true, generates postgres-specific sql
that performs an upsert operation."
Expand Down

0 comments on commit ce1ddc3

Please sign in to comment.