|
456 | 456 | *plus* other clauses). |
457 | 457 |
|
458 | 458 | (where+ {} [:id 1 {:limit 10}]) -> {:where [:= :id 1], :limit 10}" |
459 | | - [honeysql-form args] |
| 459 | + [model honeysql-form args] |
460 | 460 | (loop [honeysql-form honeysql-form, [first-arg & [second-arg & more, :as butfirst]] args] |
461 | 461 | (cond |
462 | | - (keyword? first-arg) (recur (where honeysql-form first-arg second-arg) more) |
| 462 | + (keyword? first-arg) (recur (where honeysql-form first-arg |
| 463 | + (models/do-type-fn model first-arg second-arg :in)) more) |
463 | 464 | first-arg (recur (merge honeysql-form first-arg) butfirst) |
464 | 465 | :else honeysql-form))) |
465 | 466 |
|
|
486 | 487 | {:pre [(some? id) (map? kvs) (every? keyword? (keys kvs))]} |
487 | 488 | (let [model (resolve-model model) |
488 | 489 | primary-key (models/primary-key model) |
489 | | - kvs (-> (models/do-pre-update model (assoc kvs primary-key id)) |
490 | | - (dissoc primary-key)) |
| 490 | + kvs-with-pk (models/do-pre-update model (assoc kvs primary-key id)) |
| 491 | + kvs (dissoc kvs-with-pk primary-key) |
491 | 492 | updated? (update! model (-> (h/sset {} kvs) |
492 | | - (where primary-key id)))] |
| 493 | + (where primary-key (primary-key kvs-with-pk))))] |
493 | 494 | (when (and updated? |
494 | 495 | (method-implemented? :post-update model)) |
495 | 496 | (models/post-update (model id))) |
|
608 | 609 | {:pre [(map? row-map) (every? keyword? (keys row-map))]} |
609 | 610 | (let [model (resolve-model model)] |
610 | 611 | (when-let [id (simple-insert! model (models/do-pre-insert model row-map))] |
611 | | - (models/post-insert (model id))))) |
| 612 | + (models/post-insert (model (models/do-type-fn model (models/primary-key model) id :out)))))) |
612 | 613 | ([model k v & more] |
613 | 614 | (insert! model (apply array-map k v more)))) |
614 | 615 |
|
|
624 | 625 | {:style/indent 1} |
625 | 626 | [model & options] |
626 | 627 | (let [fields (model->fields model)] |
627 | | - (simple-select-one model (where+ {:select (or fields [:*])} options)))) |
| 628 | + (simple-select-one model (where+ (resolve-model model) {:select (or fields [:*])} options)))) |
628 | 629 |
|
629 | 630 | (defn select-one-field |
630 | 631 | "Select a single `field` of a single object from the database. |
|
659 | 660 | (select 'Database :name [:not= nil] {:limit 2}) -> [...]" |
660 | 661 | {:style/indent 1} |
661 | 662 | [model & options] |
662 | | - (simple-select model (where+ {:select (or (model->fields model) |
| 663 | + (simple-select model (where+ (resolve-model model) |
| 664 | + {:select (or (model->fields model) |
663 | 665 | [:*])} |
664 | 666 | options))) |
665 | 667 |
|
|
670 | 672 | -> [\"name1\", \"name2\"]" |
671 | 673 | {:style/indent 1} |
672 | 674 | [model & options] |
673 | | - (simple-select-reducible model (where+ {:select (or (model->fields model) |
| 675 | + (simple-select-reducible model (where+ (resolve-model model) |
| 676 | + {:select (or (model->fields model) |
674 | 677 | [:*])} |
675 | 678 | options))) |
676 | 679 |
|
|
768 | 771 | primary-key (models/primary-key model)] |
769 | 772 | (doseq [object (apply select model conditions)] |
770 | 773 | (models/pre-delete object) |
771 | | - (simple-delete! model primary-key (primary-key object))))) |
| 774 | + (simple-delete! model primary-key |
| 775 | + (models/do-type-fn model primary-key (primary-key object) :in))))) |
0 commit comments