Permalink
Browse files

add database operations

  • Loading branch information...
1 parent 2cbe3a2 commit 2b0b61ec536d364fa4438ac872796b0daa8d62f7 @sunng87 committed Feb 27, 2012
Showing with 52 additions and 5 deletions.
  1. +1 −1 project.clj
  2. +45 −0 src/karmalet/db.clj
  3. +4 −2 src/karmalet/vmc.clj
  4. +2 −2 src/lobos/migrations.clj
View
@@ -4,7 +4,7 @@
[compojure "1.0.1"]
[clj-http "0.3.2"]
[cheshire "2.2.0"]
- [korma "0.3.0-beta4"]
+ [korma "0.2.1"]
[com.rabbitmq/amqp-client "2.7.1"]
[clj-time "0.3.7"]
[mysql/mysql-connector-java "5.1.8"]
View
@@ -0,0 +1,45 @@
+(ns karmalet.db
+ (:use [karmalet.vmc])
+ (:use [korma core db]))
+
+(defn- db-info []
+ (if (vmc?)
+ {:db (mysql-db)
+ :port (mysql-port)
+ :host (mysql-host)
+ :user (mysql-user)
+ :password (mysql-password)}
+ {:db "karmalet"
+ :port 3306
+ :host "localhost"
+ :user "karmalet"
+ :password "karmalet"}))
+
+(defdb conn (mysql (db-info)))
+
+(defentity kusers)
+(defentity karma)
+
+(defn find-unupdated-100-users []
+ (select kusers
+ (fields [:id])
+ (order :lastupdate :ASC)
+ (limit 100)))
+
+(defn find-service-by-users [id]
+ (select karma
+ (where {:user_id id})))
+
+(defn update-service-karma [id k]
+ (update karma
+ (set-fields {:karma k})
+ (where {:id id})))
+
+(defn add-service [userid kv]
+ (let [mk-data (fn [k v] {:user_id userid :service k :karma v})
+ data (map #(apply mk-data %) kv)]
+ (insert karma
+ (values data))))
+
+
+
View
@@ -11,7 +11,7 @@
(get service)
first
(get :credentials)
- (get key))))))
+ (get key)))))
(def mongo-config
(partial vmc-service-config :mongodb-1.8))
@@ -47,10 +47,12 @@
(mysql-config :user))
(defn mysql-password []
(mysql-config :password))
+(defn mysql-db []
+ (mysql-config :name))
(def rabbitmq-config
(partial vmc-service-config :rabbitmq-2.4))
-(def rabbitmq-url []
+(defn rabbitmq-url []
(rabbitmq-config :url))
(defn vmc? []
View
@@ -21,11 +21,11 @@
(up []
(create
(table :karma (integer :id :primary-key :auto-inc)
- (integer :user-id :not-null)
+ (integer :user_id :not-null)
(integer :service :not-null)
(integer :karma :not-null)
(integer :karma_alt)))
- (index :karma [:user-id]))
+ (index :karma [:user_id]))
(down []
(drop (table :karma))))

0 comments on commit 2b0b61e

Please sign in to comment.