Skip to content

Instantly share code, notes, and snippets.

@anarcher
Created September 5, 2010 15:36
Show Gist options
  • Save anarcher/566093 to your computer and use it in GitHub Desktop.
Save anarcher/566093 to your computer and use it in GitHub Desktop.
MongoDB-SoySauce-sketch
val db = MongoDB("hotflow")
db('post) < ("postId" -> 1212 ) :: ("post" -> "text" ) :: ("username" -> "anarcher") :: Nil
db 'post ? ("postId" -> 121) | (0,10)
db('post).find( ("postId" -> 121) ).limit(10).offset(0)
db.getMongoDb
db.getCollection("post")
import com.mongodb._
object MongoDB {
def apply(dbName: String,colName: String,host:String="localhost",port:Int= 27017) = {
val m = new MongoDB(host,port)
val db = m.getDB(dbName)
val col = db.getCollection(colName)
col
}
}
object Post extends MongoDBSchema {
val postId = MongoDBLong
val post = MongoDBString
def apply( ...
}
Post(("postId" -> 1) ) validate
type Schema = {
val fields : List[String]
val required : List[String]
}
trait PostId {
val fields = "postId" :: Nil
val required = "postId" :: Nil
}
trait UserName {
val fields = "userName" :: Nil
val required = "userName"
}
trait PostIdAndUsername extends PostId with UserName
------------------------------------------------------------------------------------------------------
trait PostId extends Schema {
var postId : MongoDBInt = MongoDBInt
}
trait Post extends Schema {
var post : MongoDBString = _
}
col.findOne[PostId,Post](q('postId -> 1 ))
// MongoDBObject extends PostId with Post
@outsideris
Copy link

계정을 날리니까 코멘트도 지워지는군요... 죄송.. ㅎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment