{"id":13481582,"url":"https://github.com/tminglei/slick-pg","last_synced_at":"2025-05-14T08:10:03.802Z","repository":{"id":536351,"uuid":"9962724","full_name":"tminglei/slick-pg","owner":"tminglei","description":"Slick extensions for PostgreSQL","archived":false,"fork":false,"pushed_at":"2025-04-27T22:28:45.000Z","size":2584,"stargazers_count":841,"open_issues_count":114,"forks_count":181,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-27T23:25:05.123Z","etag":null,"topics":["postgres","scala","slick","slick-extension"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tminglei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-05-09T15:57:40.000Z","updated_at":"2025-04-27T22:28:49.000Z","dependencies_parsed_at":"2023-12-19T14:56:06.442Z","dependency_job_id":"caab5664-b0aa-42ce-ab37-93d0100e7106","html_url":"https://github.com/tminglei/slick-pg","commit_stats":{"total_commits":953,"total_committers":102,"mean_commits":9.343137254901961,"dds":0.3683105981112277,"last_synced_commit":"4dd0dcb7d6dd51ad5d790a1612df38ebf4535306"},"previous_names":[],"tags_count":106,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminglei%2Fslick-pg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminglei%2Fslick-pg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminglei%2Fslick-pg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminglei%2Fslick-pg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tminglei","download_url":"https://codeload.github.com/tminglei/slick-pg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101559,"owners_count":22014908,"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":["postgres","scala","slick","slick-extension"],"created_at":"2024-07-31T17:00:53.052Z","updated_at":"2025-05-14T08:09:58.792Z","avatar_url":"https://github.com/tminglei.png","language":"Scala","funding_links":[],"categories":["Table of Contents","Database"],"sub_categories":["Database"],"readme":"Slick-pg\n========\n\n[![Join the chat at https://gitter.im/tminglei/slick-pg](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tminglei/slick-pg?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[Slick](https://github.com/slick/slick \"Slick\") extensions for PostgreSQL, to support a series of pg data types and related operators/functions.\n\n#### Currently supported pg types:\n- ARRAY\n- Date/Time\n- Enum\n- Range\n- Hstore\n- LTree\n- JSON\n- Inet/MacAddr\n- `text` Search\n- `postgis` Geometry\n\n#### Currently supported pg features:\n- inherits\n- composite type (`basic`)\n- aggregate functions\n- window functions\n- Large Object\n- Pg_trgm\n\n\n** _Tested on `PostgreSQL 11/12/13/14` with `Slick 3.6.0`._  \n** _`Java 8`+ is required (except for `play-json` addon, which requires `java 11`+)._  \n\n\n\nUsage\n------\nBefore using it, you need integrate it with PostgresDriver maybe like this:\n\n```scala\nimport com.github.tminglei.slickpg._\n\n\ntrait MyPostgresProfile extends ExPostgresProfile\n                          with PgArraySupport\n                          with PgDate2Support\n                          with PgRangeSupport\n                          with PgHStoreSupport\n                          with PgPlayJsonSupport\n                          with PgSearchSupport\n                          with PgPostGISSupport\n                          with PgNetSupport\n                          with PgLTreeSupport {\n  def pgjson = \"jsonb\" // jsonb support is in postgres 9.4.0 onward; for 9.3.x use \"json\"\n\n  // Add back `capabilities.insertOrUpdate` to enable native `upsert` support; for postgres 9.5+\n  override protected def computeCapabilities: Set[slick.basic.Capability] =\n    super.computeCapabilities + slick.jdbc.JdbcCapabilities.insertOrUpdate\n\n  override val api = MyAPI\n\n  object MyAPI extends ExtPostgresAPI with ArrayImplicits\n                                      with Date2DateTimeImplicitsDuration\n                                      with JsonImplicits\n                                      with NetImplicits\n                                      with LTreeImplicits\n                                      with RangeImplicits\n                                      with HStoreImplicits\n                                      with SearchImplicits\n                                      with SearchAssistants {\n    implicit val strListTypeMapper = new SimpleArrayJdbcType[String](\"text\").to(_.toList)\n    implicit val playJsonArrayTypeMapper =\n      new AdvancedArrayJdbcType[JsValue](pgjson,\n        (s) =\u003e utils.SimpleArrayUtils.fromString[JsValue](Json.parse(_))(s).orNull,\n        (v) =\u003e utils.SimpleArrayUtils.mkString[JsValue](_.toString())(v)\n      ).to(_.toList)\n  }\n}\n\nobject MyPostgresProfile extends MyPostgresProfile\n\n```\n\nthen in your codes you can use it like this:\n```scala\nimport MyPostgresProfile.api._\n\nclass TestTable(tag: Tag) extends Table[Test](tag, Some(\"xxx\"), \"Test\") {\n  def id = column[Long](\"id\", O.AutoInc, O.PrimaryKey)\n  def during = column[Range[Timestamp]](\"during\")\n  def location = column[Point](\"location\")\n  def text = column[String](\"text\", O.DBType(\"varchar(4000)\"))\n  def props = column[Map[String,String]](\"props_hstore\")\n  def tags = column[List[String]](\"tags_arr\")\n\n  def * = (id, during, location, text, props, tags) \u003c\u003e ((Test.apply _).tupled, Test.unapply)\n}\n\nobject tests extends TableQuery(new TestTable(_)) {\n  // will generate sql like:\n  //   select * from test where id = ?\n  def byId(ids: Long*) = tests\n        .filter(_.id inSetBind ids)\n        .map(t =\u003e t)\n  // will generate sql like:\n  //   select * from test where tags \u0026\u0026 ?\n  def byTag(tags: String*) = tests\n        .filter(_.tags @\u0026 tags.toList.bind)\n        .map(t =\u003e t)\n  // will generate sql like:\n  //   select * from test where during \u0026\u0026 ?\n  def byTsRange(tsRange: Range[Timestamp]) = tests\n        .filter(_.during @\u0026 tsRange.bind)\n        .map(t =\u003e t)\n  // will generate sql like:\n  //   select * from test where case(props -\u003e ? as [T]) == ?\n  def byProperty[T](key: String, value: T) = tests\n        .filter(_.props.\u003e\u003e[T](key.bind) === value.bind)\n        .map(t =\u003e t)\n  // will generate sql like:\n  //   select * from test where ST_DWithin(location, ?, ?)\n  def byDistance(point: Point, distance: Int) = tests\n        .filter(r =\u003e r.location.dWithin(point.bind, distance.bind))\n        .map(t =\u003e t)\n  // will generate sql like:\n  //   select id, text, ts_rank(to_tsvector(text), to_tsquery(?))\n  //   from test where to_tsvector(text) @@ to_tsquery(?)\n  //   order by ts_rank(to_tsvector(text), to_tsquery(?))\n  def search(queryStr: String) = tests\n        .filter( t =\u003e {tsVector(t.text) @@ tsQuery(queryStr.bind)})\n        .map(r =\u003e (r.id, r.text, tsRank(tsVector(r.text), tsQuery(queryStr.bind))))\n        .sortBy(_._3)\n}\n\n...\n```\n\n_p.s. The code samples above are for `Slick` Lifted Embedding SQL. Aside from that, `slick-pg` also supports `Slick` Plain SQL--for details and usages please refer to source code and tests._\n\n\nConfigurable type/mappers\n-------------------------\nSince v0.2.0, `slick-pg` started to support configurable type/mappers.\n\nHere's the related technical details:\n\u003e All pg type oper/functions related codes and some core type mapper logics were extracted to a new sub project \"slick-pg_core\", and the oper/functions and type/mappers binding related codes were retained in the main project \"slick-pg\".\n\n**So, if you need bind different scala type/mappers to a pg type oper/functions, you can do it as \"slick-pg\" currently did.**\n\n\n#### Built in supported type/mappers\n\n| scala Type                                                                                               | pg Type               | dev 3rd-party library dependency     |\n|----------------------------------------------------------------------------------------------------------| --------------------- |--------------------------------------|\n| List[T]                                                                                                  | ARRAY                 | no 3rd party dependencies            |\n| `java.sql` Date \u003cbr\u003e Time\u003cbr\u003e Timestamp\u003cbr\u003e slickpg Interval\u003cbr\u003e Calendar                                | date\u003cbr\u003e time\u003cbr\u003e timestamp\u003cbr\u003e interval\u003cbr\u003e timestamptz | no 3rd party dependencies            |\n| `java.time` LocalDate\u003cbr\u003e LocalTime\u003cbr\u003e LocalDateTime\u003cbr\u003e Duration\u003cbr\u003e ZonedDateTime \u003cbr\u003e OffsetDateTime | date\u003cbr\u003e time\u003cbr\u003e timestamp\u003cbr\u003e interval\u003cbr\u003e timestamptz \u003cbr\u003e timestamptz | (built-in) no 3rd party dependencies |\n| `joda` LocalDate\u003cbr\u003e LocalTime\u003cbr\u003e LocalDateTime\u003cbr\u003e Period\u003cbr\u003e DateTime                                 | date\u003cbr\u003e time\u003cbr\u003e timestamp\u003cbr\u003e interval\u003cbr\u003e timestamptz | `joda-time` v2.12.7                  |\n| `scala` Enumeration                                                                                      | enum                  | no 3rd party dependencies            |\n| `slickpg` Range[T]                                                                                       | range                 | no 3rd party dependencies            |\n| `slickpg` LTree                                                                                          | ltree                 | no 3rd party dependencies            |\n| Map[String,String]                                                                                       | hstore                | no 3rd party dependencies            |\n| `slickpg` InetString                                                                                     | inet                  | no 3rd party dependencies            |\n| `slickpg` MacAddrString                                                                                  | macaddr               | no 3rd party dependencies            |\n| `slickpg` JsonString                                                                                     | json                  | no 3rd party dependencies            |\n| `json4s` JValue                                                                                          | json                  | `json4s` v4.0.7                      |\n| `play-json` JsValue                                                                                      | json                  | `play-json` v2.10 or v3.0            |\n| `spray-json` JsValue                                                                                     | json                  | `spray-json` v1.3.5                  |\n| `argonaut json` Json                                                                                     | json                  | `argonaut` v6.3.9                    |\n| `circe json` Json                                                                                        | json                  | `circe` v0.14.6                      |\n| `uPickle json` Json                                                                                      | json                  | `uPickle` v3.1.4                     |\n| `jawn json` Json                                                                                         | json                  | `jawn` v1.5.1                        |\n| (TsQuery+TsVector)                                                                                       | `text` search         | no 3rd party dependencies            |\n| `jts` Geometry                                                                                           | `postgis` geometry    | `jts` v1.14.0                        |\n| `locationtech's jts` Geometry                                                                            | `postgis` geometry    | locationtech's `jts` v1.19.0         |\n\n_**Warning:** When your work with time data that contain Timezone, be wary of your postgres configuration. By default `ZonedDateTime` in Java 8 contains more information than `timestamptz` in Postgres. As a consequence, when you store a `ZonedDateTime` you are not guaranteed to get the same timezone as the original class instance. Prefer `OffsetDateTime` instead. cf [Issue #248](https://github.com/tminglei/slick-pg/issues/248)_\n\nDetails\n------------------------------\n- Array's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/array \"Array's oper/functions\"), usage  [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgArraySupportSuite.scala \"test cases\")\n- JSON's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/json \"JSON's oper/functions\"), usage cases for [json4s](https://github.com/tminglei/slick-pg/blob/master/addons/json4s/src/test/scala/com/github/tminglei/slickpg/PgJson4sSupportSuite.scala \"test cases\"), [play-json](https://github.com/tminglei/slick-pg/blob/master/addons/play-json/src/test/scala/com/github/tminglei/slickpg/PgPlayJsonSupportSuite.scala \"test cases\"), [spray-json](https://github.com/tminglei/slick-pg/blob/master/addons/spray-json/src/test/scala/com/github/tminglei/slickpg/PgSprayJsonSupportSuite.scala \"test cases\"), [upickle json](https://github.com/tminglei/slick-pg/blob/master/addons/upickle-json/src/test/scala/com/github/tminglei/slickpg/PgUPickleJsonSupportSuite.scala \"test cases\") and [argonaut json](https://github.com/tminglei/slick-pg/blob/master/addons/argonaut/src/test/scala/com/github/tminglei/slickpg/PgArgonautSupportSuite.scala \"test cases\")\n- Date/Time's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/date \"Date/Time's oper/functions\"), usage cases for [java date](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgDateSupportSuite.scala \"test cases\"), [java 8 date](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgDate2SupportSuite.scala \"test cases\") and [joda time](https://github.com/tminglei/slick-pg/blob/master/addons/joda-time/src/test/scala/com/github/tminglei/slickpg/PgDateSupportJodaSuite.scala \"test cases\")\n- Enum's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/enums \"Enum's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala \"test cases\")\n- Range's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/range \"Range's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgRangeSupportSuite.scala \"test cases\")\n- HStore's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/hstore \"HStore's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgHStoreSupportSuite.scala \"test cases\")\n- LTree's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/ltree \"LTree's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgLTreeSupportSuite.scala \"test cases\")\n- PgTrgm's [oper/functions](https://github.com/tminglei/slick-pg/blob/master/core/src/main/scala/com/github/tminglei/slickpg/trgm \"PgTrgm's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/core/src/test/scala/com/github/tminglei/slickpg/trgm/PgTrgmSupportSuite.scala \"test cases\")\n- Inet/MacAddr's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/net \"net's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgNetSupportSuite.scala \"test cases\")\n- Search's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/search \"Search's oper/functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgSearchSupportSuite.scala \"test cases\")\n- Geometry's [oper/functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/geom \"Geometry's oper/functions\"), usage cases for [postgis](https://github.com/tminglei/slick-pg/blob/master/addons/jts/src/test/scala/com/github/tminglei/slickpg/PgPostGISSupportSuite.scala \"test cases\")\n- `basic` Composite type [support](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/composite \"Composite type Support\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgCompositeSupportSuite.scala \"test cases\")\n- Aggregate [functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/agg \"Aggregate functions\"), usage [cases](https://github.com/tminglei/slick-pg/blob/master/core/src/test/scala/com/github/tminglei/slickpg/PgAggFuncSupportSuite.scala)\n- Window [functions](https://github.com/tminglei/slick-pg/tree/master/core/src/main/scala/com/github/tminglei/slickpg/window), usage [cases](https://github.com/tminglei/slick-pg/blob/master/core/src/test/scala/com/github/tminglei/slickpg/PgWindowFuncSupportSuite.scala)\n\n\n\nInstall\n-------\nTo use `slick-pg` in [sbt](http://www.scala-sbt.org/ \"slick-sbt\") project, add the following to your project file:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg\" % \"0.23.0\"\n```\n\n\u003e If you need `joda-time` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_joda-time\" % \"0.23.0\"\n```\n\n\u003e If you need `jts` geom support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_jts\" % \"0.23.0\"\nor\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_jts_lt\" % \"0.23.0\"\n```\n\n\u003e If you need `json4s` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_json4s\" % \"0.23.0\"\n```\n\n\u003e If you need `play-json` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_play-json\" % \"0.23.0\"\nor\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_play-json3\" % \"0.23.0\"\n```\n\n\u003e If you need `spray-json` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_spray-json\" % \"0.23.0\"\n```\n\n\u003e If you need `argonaut json` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_argonaut\" % \"0.23.0\"\n```\n\n\u003e If you need `circe json` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_circe-json\" % \"0.23.0\"\n```\n\n\u003e If you need `uPickle json` support, pls append dependency:\n```scala\nlibraryDependencies += \"com.github.tminglei\" %% \"slick-pg_upickle-json\" % \"0.23.0\"\n```\n\n\nOr, in [maven](http://maven.apache.org/ \"maven\") project, you can add `slick-pg` to your `pom.xml` like this:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.tminglei\u003c/groupId\u003e\n    \u003cartifactId\u003eslick-pg_2.13\u003c/artifactId\u003e\n    \u003cversion\u003e0.23.0\u003c/version\u003e\n\u003c/dependency\u003e\n\u003c!-- other addons if necessary --\u003e\n...\n```\n\n**Notes:**\n- the plugins' code were ever merged to the main project and published in an all-in-one jar from `slick-pg` v0.7.0, to easy usage, but I restored to publish them as independent jars from `slick-pg` v0.10.0, because of the issue pointed out by @timcharper in #183.\n- plugin `slick-pg_date2` was merged into major jar from `slick-pg` v0.15.0, so you needn't add it as a depencensy any more.\n\n\n\nBuild instructions\n------------------\n`slick-pg` uses SBT for building and requires Java 8, since it provides support for `java.date` in addon `date2`. Assume you have already installed SBT, then you can simply clone the git repository and build `slick-pg` in the following way:\n```\n./sbt update\n./sbt compile\n```\n\n_To run the test suite, you need:_\n- create a user 'test' and db 'test' on your local postgres server, and\n- the user 'test' should be an super user and be the owner of db 'test'\n\nThen you can run the tests like this:\n```\n./sbt test\n```\n_ps: in the code of unit tests, the `slick` database is setup like this:_\n```scala\nval db = Database.forURL(url = \"jdbc:postgresql://localhost/test?user=postgres\", driver = \"org.postgresql.Driver\")\n```\n\n\nLicense\n-------\nLicensing conditions (BSD-style) can be found in LICENSE.txt.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftminglei%2Fslick-pg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftminglei%2Fslick-pg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftminglei%2Fslick-pg/lists"}