<commit_before>(ns metabase.api.meta.db
  "/api/meta/db endpoints."
  (:require [compojure.core :refer [GET POST PUT DELETE]]
            [korma.core :refer :all]
            [medley.core :as medley]
            [metabase.api.common :refer :all]
            [metabase.db :refer :all]
            [metabase.driver :as driver]
            [metabase.driver.sync :as sync]
            (metabase.models common
                             [hydrate :refer [hydrate]]
                             [database :refer [Database]]
                             [field :refer [Field]]
                             [org :refer [org-can-read org-can-write]]
                             [table :refer [Table]])))

(defendpoint GET "/" [org]
  (check-403 (org-can-read org))
  (-> (sel :many Database :organization_id org (order :name))
      (hydrate :organization)))

(defendpoint POST "/" [:as {{:keys [org] :as body} :body}]
  (check-403 (org-can-write org))
  (->> (-> body
           (select-keys [:name :engine :details])
           (assoc :organization_id org))
       (medley/mapply ins Database)))

(defendpoint GET "/form_input" []
  {:timezones metabase.models.common/timezones
   :engines driver/available-drivers})

(defendpoint GET "/:id" [id]
  (->404 (sel :one Database :id id)
         (hydrate :organization)))

(defendpoint PUT "/:id" [id :as {{:keys [name engine details]} :body}]
  (println name engine details)
  (write-check Database id)<commit_msg>api/meta/db should return 400 if you forget to pass 'org', not 403<commit_after>(ns metabase.api.meta.db
  "/api/meta/db endpoints."
  (:require [compojure.core :refer [GET POST PUT DELETE]]
            [korma.core :refer :all]
            [medley.core :as medley]
            [metabase.api.common :refer :all]
            [metabase.db :refer :all]
            [metabase.driver :as driver]
            [metabase.driver.sync :as sync]
            (metabase.models common
                             [hydrate :refer [hydrate]]
                             [database :refer [Database]]
                             [field :refer [Field]]
                             [org :refer [org-can-read org-can-write]]
                             [table :refer [Table]])))

(defendpoint GET "/" [org]
  (require-params org)
  (check-403 (org-can-read org))
  (-> (sel :many Database :organization_id org (order :name))
      (hydrate :organization)))

(defendpoint POST "/" [:as {{:keys [org] :as body} :body}]
  (check-403 (org-can-write org))
  (->> (-> body
           (select-keys [:name :engine :details])
           (assoc :organization_id org))
       (medley/mapply ins Database)))

(defendpoint GET "/form_input" []
  {:timezones metabase.models.common/timezones
   :engines driver/available-drivers})

(defendpoint GET "/:id" [id]
  (->404 (sel :one Database :id id)
         (hydrate :organization)))

(defendpoint PUT "/:id" [id :as {{:keys [name engine details]} :body}]
  (println name engine details)
  (write-check Database id)
{'fraction_non_alphanumeric': 0.1465863453815261, 'fraction_numerical': 0.008032128514056224, 'mean_word_length': 2.116788321167883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1436621', 'n_tokens_mistral': 962, 'n_tokens_neox': 934, 'n_words': 252}