{"id":13695721,"url":"https://github.com/cloudinsights/play-salat","last_synced_at":"2025-05-03T13:33:04.016Z","repository":{"id":57737029,"uuid":"49745297","full_name":"cloudinsights/play-salat","owner":"cloudinsights","description":null,"archived":false,"fork":false,"pushed_at":"2016-05-03T15:48:10.000Z","size":167,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-03T18:19:52.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudinsights.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-15T21:15:41.000Z","updated_at":"2018-02-05T16:58:56.000Z","dependencies_parsed_at":"2022-08-24T14:59:39.743Z","dependency_job_id":null,"html_url":"https://github.com/cloudinsights/play-salat","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudinsights%2Fplay-salat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudinsights%2Fplay-salat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudinsights%2Fplay-salat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudinsights%2Fplay-salat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudinsights","download_url":"https://codeload.github.com/cloudinsights/play-salat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224364361,"owners_count":17299055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:32.771Z","updated_at":"2024-11-12T23:30:47.820Z","avatar_url":"https://github.com/cloudinsights.png","language":"Scala","funding_links":[],"categories":["Resources for old Play version (before 2.6)"],"sub_categories":["Others"],"readme":"# Disclaimer\n**This is continuation of Leon's [play-salat plugin](https://github.com/leon/play-salat) for future versions of play and is comptabile with latest version of play 2.4.6. Update your Build.scala or build.sbt with my artifactId**\n\n# MongoDB Salat plugin for Play Framework 2\nSalat is a ORM for MongoDBs scala driver called Casbah.\n\nThe plugin's functionality simpifies the use of salat by presenting a simple \"play style\" configuration and binders for `ObjectId`\n\n * https://github.com/mongodb/casbah\n * https://github.com/novus/salat\n\n\n## Installation\n\nUse g8 to start a new salat enabled play project\n\n### Install g8 on OSX using homebrew\n\n    brew update \u0026\u0026 brew install giter8\n\nOr read about the other ways to install [giter8 here](https://github.com/n8han/giter8)\n\nThen run\n\n    g8 leon/play-salat.g8\n\nIt will ask you a couple of questions, and your ready to rock 'n roll.\n\n### Manual installation\nStart by adding the plugin, in your `project/Build.scala`\n````scala\nval appDependencies = Seq(\n  \"net.cloudinsights\" %% \"play-plugins-salat\" % \"1.5.9\"\n)\n````\nThen we can add the implicit converstions to and from ObjectId by adding to the routesImport and add ObjectId to all the templates\n\n**Play 2.2.x and previous**\n\n````scala\nval main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(\n  routesImport += \"se.radley.plugin.salat.Binders._\",\n  templatesImport += \"org.bson.types.ObjectId\"\n)\n````\n**Play 2.3.x and subsequent**\n\n````scala\nimport play.twirl.sbt.Import.TwirlKeys\nval main = Project(appName, file(\".\")).enablePlugins(play.PlayScala).settings(\n  routesImport += \"se.radley.plugin.salat.Binders._\",\n  TwirlKeys.templateImports += \"org.bson.types.ObjectId\"\n)\n````\n\nWe now need to register the plugin, this is done by creating(or appending) to the `conf/play.plugins` file\n\n    500:se.radley.plugin.salat.SalatPlugin\n\nWe continue to edit the `conf/application.conf` file. We need to disable some plugins that we don't need.\nAdd these lines:\n\n    dbplugin = disabled\n    evolutionplugin = disabled\n    ehcacheplugin = disabled\n\n## Configuration\nnow we need to setup our connections. The plugin is modeled after how plays DB plugin is built.\n\n    mongodb.default.db = \"mydb\"\n    # Optional values\n    #mongodb.default.host = \"127.0.0.1\"\n    #mongodb.default.port = 27017\n    #mongodb.default.user = \"leon\"\n    #mongodb.default.password = \"123456\"\n\n\t# MongoURI\n\t# ~~~~~\n\t# a MongoURI can also be used http://www.mongodb.org/display/DOCS/Connections\n\t# mongodb.default.uri = \"mongodb://127.0.0.1:27017,mongodb.org:1337/salat-test\"\n\n\t# WriteConcern\n\t# ~~~~~\n\t# Can be any of the following\n\t#\n\t# fsyncsafe - Exceptions are raised for network issues and server errors; Write operations wait for the server to flush data to disk.\n\t# replicassafe - Exceptions are raised for network issues and server errors; waits for at least 2 servers for the write operation.\n\t# safe - Exceptions are raised for network issues and server errors; waits on a server for the write operation.\n\t# normal - Exceptions are raised for network issues but not server errors.\n\n\t#mongodb.default.writeconcern = \"safe\"\n\n\t# Replica sets\n\t# ~~~~~\n\t# http://www.mongodb.org/display/DOCS/Why+Replica+Sets\n\t#\n\t# To user a replicaset instead of a single host, omit optional values and use the configuration below instead.\n\t# Since replica sets use public key authentication, user and password won't work together with the replicaset option.\n\n\t#mongodb.default.replicaset {\n\t#    host1.host = \"10.0.0.1\"\n\t#\n\t#    host2.host = \"10.0.0.2\"\n\t#    host2.port = 27018\n\t#}\n\n\t# Mongo Options\n\t# ~~~~~\n\t# http://api.mongodb.org/java/2.8.0/com/mongodb/MongoOptions.html\n\t#\n\t# For passing custom options to the MongoConnection add the properties under \"options\". Add just the ones which are different from defaults.\n\n\t#mongodb.default.options {\n\t#    connectionsPerHost = 100\n\t#    threadsAllowedToBlockForConnectionMultiplier = 1000\n\t#    connectTimeout = 60000\n\t#}\n\n## More that one DB?\nIf you would like to connect to two databases you need to create two source names. You also can specify different options per database\n\n    mongodb.myotherdb.db = \"otherdb\"\n    mongodb.myotherdb.options.connectionsPerHost = 80\n\nThen you can call `mongoCollection(\"collectionname\", \"myotherdb\")`\n\n## What a model looks like\nAll models must be case classes otherwise salat doesn't know how to properly transform them into MongoDBObject's\n````scala\npackage models\n\nimport play.api.Play.current\nimport java.util.Date\nimport com.novus.salat._\nimport com.novus.salat.annotations._\nimport com.novus.salat.dao._\nimport com.mongodb.casbah.Imports._\nimport se.radley.plugin.salat._\nimport mongoContext._\n\ncase class User(\n  id: ObjectId = new ObjectId,\n  username: String,\n  password: String,\n  address: Option[Address] = None,\n  added: Date = new Date(),\n  updated: Option[Date] = None,\n  deleted: Option[Date] = None,\n  @Key(\"company_id\")company: Option[ObjectId] = None\n)\n\nobject User extends ModelCompanion[User, ObjectId] {\n  val dao = new SalatDAO[User, ObjectId](collection = mongoCollection(\"users\")) {}\n\n  def findOneByUsername(username: String): Option[User] = dao.findOne(MongoDBObject(\"username\" -\u003e username))\n  def findByCountry(country: String) = dao.find(MongoDBObject(\"address.country\" -\u003e country))\n}\n````\n## Capped Collections\nIf you want to use capped collections check this out\n````scala\npackage models\n\nimport play.api.Play.current\nimport java.util.Date\nimport com.novus.salat._\nimport com.novus.salat.annotations._\nimport com.novus.salat.dao._\nimport com.mongodb.casbah.Imports._\nimport se.radley.plugin.salat._\nimport mongoContext._\n\ncase class LogItem(\n  id: ObjectId = new ObjectId,\n  message: String\n)\n\nobject LogItem extends ModelCompanion[LogItem, ObjectId] {\n  val dao = new SalatDAO[LogItem, ObjectId](collection = mongoCappedCollection(\"logitems\", 1000)) {}\n}\n````\n## GridFS\nIf you want to store things in gridfs you can do this\n````\npackage models\n\nimport play.api.Play.current\nimport se.radley.plugin.salat._\nimport mongoContext._\n\nval files = gridFS(\"myfiles\")\n````\n## Mongo Context\nAll models must contain an implicit salat Context. The context is somewhat like a hibernate dialect.\nYou can override mapping names and configure how salat does it's type hinting. read more about it [here](https://github.com/novus/salat/wiki/CustomContext)\n\nIn the sample there is a custom `mongoContext`, partly because we need to add plays classloader to salat so it knows when to reload it's graters,\nbut also so we can override all models id fields to be serialized to MongoDB's _id.\n\n- [Sample](https://github.com/leon/play-salat/tree/master/sample)\n\n## Enums?\nIf you're using Scala Enumerations have a look at my play-enumeration project.\n\n- [play-enumeration](https://github.com/leon/play-enumeration)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudinsights%2Fplay-salat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudinsights%2Fplay-salat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudinsights%2Fplay-salat/lists"}