Selaa lähdekoodia

Use sqlite instead of postgres

Thomas Dy 7 vuotta sitten
vanhempi
commit
273160290a
5 muutettua tiedostoa jossa 11 lisäystä ja 10 poistoa
  1. 1 0
      .gitignore
  2. 5 4
      app/models/Card.scala
  3. 1 1
      build.sbt
  4. 2 3
      conf/application.conf
  5. 2 2
      conf/evolutions/default/1.sql

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@ project/target
 target
 tmp
 public/components
+gamenchat.db

+ 5 - 4
app/models/Card.scala

@@ -26,14 +26,15 @@ object Card {
   }
 
   def add(card: Card) = DB.withTransaction { implicit c =>
-    val id = SQL("insert into words values (default, {word})")
+    SQL("insert into words (word) values ({word})")
       .on('word -> card.word)
-      .executeInsert()
+      .execute()
+    val id = SQL("select last_insert_rowid()").singleOpt(int("last_insert_rowid()"))
     id.map { id =>
       card.taboo.map { word =>
-        SQL("insert into taboo values (default, {id}, {word})")
+        SQL("insert into taboo (word_id, word) values ({id}, {word})")
           .on('id -> id, 'word -> word)
-          .executeInsert()
+          .execute()
       }
     }
   }

+ 1 - 1
build.sbt

@@ -6,6 +6,6 @@ version := "1.0"
 
 libraryDependencies ++= Seq(jdbc, anorm)
 
-libraryDependencies += "postgresql" % "postgresql" % "9.1-901.jdbc4"
+libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.21.0.1"
 
 playScalaSettings

+ 2 - 3
conf/application.conf

@@ -18,9 +18,8 @@ application.secret="fXYT0c[h_gT_ZtlDbpJESb=22p;R62HO5nvwgN3RI<3ZsIVu04UsP;HiMeFb
 # You can declare as many datasources as you want.
 # By convention, the default datasource is named `default`
 #
-db.default.driver=org.postgresql.Driver
-db.default.url="jdbc:postgresql:gamenchat"
-db.default.user=postgres
+db.default.driver=org.sqlite.JDBC
+db.default.url="jdbc:sqlite:./gamenchat.db"
 
 # Evolutions
 # ~~~~~

+ 2 - 2
conf/evolutions/default/1.sql

@@ -1,12 +1,12 @@
 # --- !Ups
 
 CREATE TABLE words (
-  id serial PRIMARY KEY,
+  id integer PRIMARY KEY,
   word text NOT NULL
 );
 
 CREATE TABLE taboo (
-  id serial PRIMARY KEY,
+  id integer PRIMARY KEY,
   word_id integer NOT NULL REFERENCES words(id),
   word text NOT NULL
 );