Created
January 2, 2012 15:23
-
-
Save tototoshi/1551080 to your computer and use it in GitHub Desktop.
ScalaQueryでカラムのオプションを指定する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see: https://github.com/szeiger/scala-query/blob/0.9.5/src/main/scala/org/scalaquery/ql/basic/BasicColumnOptions.scala | |
package com.github.tototoshi.example | |
import org.scalaquery._ | |
import session.{ Database, Session } | |
import ql._ | |
import basic.BasicDriver.Implicit._ | |
import basic.{ BasicTable => Table } | |
object User extends Table[(Long, String, Int)]("user") { | |
def id = column[Long]("id", O PrimaryKey) | |
def name = column[String]("user", O NotNull, O DBType "varchar(30) unique") | |
def point = column[Int]("point", O Default 0) | |
def * = id ~ name ~ point | |
} | |
object Main extends App { | |
val db = Database.forURL("jdbc:postgresql:scala_query_example", | |
driver="org.postgresql.Driver", | |
user="user", | |
password="password") | |
db withSession { implicit s: Session => | |
User.ddl.create | |
} | |
} | |
/* 実行結果 | |
scala_query_example=> \d user | |
Table "public.user" | |
Column | Type | Modifiers | |
--------+-----------------------+-------------------- | |
id | bigint | not null | |
user | character varying(30) | not null | |
point | integer | not null default 0 | |
Indexes: | |
"user_pkey" PRIMARY KEY, btree (id) | |
"user_user_key" UNIQUE CONSTRAINT, btree ("user") | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment