From feb0c9a6f872f610107bc9a7ae8df9037bc3a666 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 25 Sep 2021 17:35:02 -0700 Subject: [PATCH] fixes #347 --- CHANGELOG.md | 1 + doc/clause-reference.md | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9706580..1f1d759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Fix #363 and #362 by aligning more closely the semantics of `:inline` syntax with the `:inline true` option. A side effect of this is that `[:inline [:param :foo]]` will now (correctly) inline the value of the parameter `:foo` whereas it previously produced `PARAMS SOURCE`. In addition, inlining has been extended to vector values, so `[:inline ["a" "b" "c"]]` will now produce `('a', 'b', 'c')` and `[:inline [:lift ["a" "b" "c"]]]` will now produce `['a', 'b', 'c']` which is what people seemed to expect (the behavior was previously unspecified). * Fix #353 by correcting handling of strings used as SQL entities (such as table names); this was a regression introduced by a recent enhancement to `:create-table`. * Fix #349 by adding an optional `:quoted` argument to `set-dialect!`. + * Address #347 by adding example of adding a primary key to an existing table via `:add-index`. * Support `AS` aliasing in `DELETE FROM`. * Switch from `readme` to `test-doc-blocks` so all documentation is tested! * Clean up build/update deps. diff --git a/doc/clause-reference.md b/doc/clause-reference.md index 7409fef..6468dd5 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -18,8 +18,8 @@ The examples herein assume: ```clojure (refer-clojure :exclude '[partition-by]) (require '[honey.sql :as sql] - '[honey.sql.helpers :refer [select from join-by left-join join - where order-by over partition-by window]]) + '[honey.sql.helpers :as h :refer [select from join-by left-join join + where order-by over partition-by window]]) ``` # DDL Clauses @@ -89,6 +89,15 @@ user=> (sql/format {:alter-table :fruit :drop-index :look}) ["ALTER TABLE fruit DROP INDEX look"] ``` +You can use `:add-index` to add a primary key to an existing table, as follows: + +```clojure +user=> (-> (h/alter-table :fruit) + (h/add-index :primary-key :id) + (sql/format)) +["ALTER TABLE fruit ADD PRIMARY KEY(id)"] +``` + ### rename-table Used with `:alter-table`,