{"id":13812154,"url":"https://github.com/supabase-community/postgrest-kt","last_synced_at":"2025-05-14T21:32:20.885Z","repository":{"id":37928166,"uuid":"333849426","full_name":"supabase-community/postgrest-kt","owner":"supabase-community","description":"Postgrest Kotlin Client","archived":true,"fork":false,"pushed_at":"2023-11-01T17:55:46.000Z","size":105,"stargazers_count":53,"open_issues_count":6,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-08T08:02:49.768Z","etag":null,"topics":["android","java","jvm","kotlin","postgresql","postgrest","supabase"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supabase-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-01-28T18:30:31.000Z","updated_at":"2024-07-04T12:51:35.000Z","dependencies_parsed_at":"2024-08-04T04:01:55.747Z","dependency_job_id":"f05e524a-11a0-471f-b057-6cc6c14c9db9","html_url":"https://github.com/supabase-community/postgrest-kt","commit_stats":null,"previous_names":["supabase/postgrest-kt"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-kt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-kt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-kt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-kt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supabase-community","download_url":"https://codeload.github.com/supabase-community/postgrest-kt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036842,"owners_count":22003654,"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":["android","java","jvm","kotlin","postgresql","postgrest","supabase"],"created_at":"2024-08-04T04:00:48.083Z","updated_at":"2025-05-14T21:32:20.810Z","avatar_url":"https://github.com/supabase-community.png","language":"Kotlin","funding_links":[],"categories":["Postgrest"],"sub_categories":[],"readme":"# Kotlin Client for PostgREST\r\n\r\n\u003e **Warning**\r\n\u003e This repository is archived. Use [supabase-kt](https://github.com/supabase-community/supabase-kt) instead to use Supabase in your Kotlin projects.\r\n\r\nKotlin JVM client for [PostgREST](https://postgrest.org/)\r\n\r\n![Java CI with Gradle](https://img.shields.io/github/workflow/status/supabase/postgrest-kt/Java%20CI%20with%20Gradle?label=BUILD\u0026style=for-the-badge)\r\n![Gradle Package](https://img.shields.io/github/workflow/status/supabase/postgrest-kt/Gradle%20Package?label=PUBLISH\u0026style=for-the-badge)\r\n![Bintray](https://img.shields.io/bintray/v/supabase/supabase/postgrest-kt?style=for-the-badge)\r\n\r\n## Installation\r\n\r\nMaven\r\n\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003eio.supabase\u003c/groupId\u003e\r\n    \u003cartifactId\u003epostgrest-kt\u003c/artifactId\u003e\r\n    \u003cversion\u003e{version}\u003c/version\u003e\r\n    \u003ctype\u003epom\u003c/type\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\nGradle\r\n\r\n```\r\nimplementation 'io.supabase:postgrest-kt:{version}'\r\n```\r\n\r\n## Usage\r\n\r\n### Initializing the client\r\n\r\n```kotlin\r\nval postgrestClient =  PostgrestDefaultClient(\r\n    uri = URI(\"http://localhost:3111\"),\r\n    headers = mapOf(\"Authorization\" to \"foobar\")\r\n)\r\n```\r\n\r\nYou can also pass in a custom schema using the `schema` parameter.\r\n\r\n### Entry points\r\n\r\nThere are two methods to start any call on the PostgresClient.\r\n\r\n#### from\u003cT\u003e\r\n\r\nThe `from\u003cT\u003e` function is used for querying.\r\nIt takes a generic parameter to allow for auto-completion when defining column names.\r\nHowever, you can always use `Any` if you are unsure about the data type.\r\n\r\n```kotlin\r\npostgresClient.from\u003cAny\u003e(\"messages\")\r\n    .select()\r\n    .neq(\"content\", \"abc\")\r\n    .execute()\r\n\r\npostgresClient.from\u003cMessage\u003e(\"messages\")\r\n    .select()\r\n    .neq(Message::content, \"abc\")\r\n    .execute()\r\n\r\n// select item_id AS itemId, age from messages...\r\npostgresClient.from\u003cMessage\u003e(\"messages\")\r\n    .select(\"itemId:item_id,age\")\r\n    .neq(Message::content, \"abc\")\r\n    .execute()\r\n\r\n// https://postgrest.org/en/stable/api.html#embedding-top-level-filter\r\npostgresClient.from\u003cMessage\u003e(\"messages\")\r\n    .select(\"name,age,company(name, address, phone)\")\r\n    .neq(Message::content, \"abc\")\r\n    .execute()\r\n```\r\n\r\n#### rpc\u003cT\u003e\r\n\r\nThe `rpc\u003cT\u003e` function executes a stored procedure.\r\n\r\n```kotlin\r\npostgresClient.rpc(\"get_status\", mapOf(\"foo\" to \"bar\"))\r\n    .execute()\r\n```\r\n\r\n### Executing requests\r\n\r\nThere are three ways to execute requests and read the response.\r\n\r\n#### execute\r\n\r\nThe `execute` method returns a [PostgrestHttpResponse](src/main/kotlin/io/supabase/postgrest/http/PostgrestHttpResponse.kt).\r\nThe HttpResponse contains the status code, body as string and the count (if you request the count).\r\n\r\n```kotlin\r\nval response = postgresClient.from\u003cAny\u003e(\"messages\")\r\n    .select()\r\n    .execute()\r\n\r\nprintln(response.body)\r\nprintln(response.status)\r\nprintln(response.count)\r\n```\r\n\r\n#### executeAndGetSingle\u003cT\u003e\r\n\r\nThe `executeAndGetSingle\u003cT\u003e` function returns `T`.\r\nThe JSON converter is used to convert the response to the DTO.\r\n\r\n```kotlin\r\ndata class Message(\r\n    val id: Long,\r\n    val content: String\r\n)\r\n\r\nval message = postgresClient.from\u003cMessage\u003e(\"messages\")\r\n    .select()\r\n    .eq(Message::id, 123L)\r\n    .limit(1)\r\n    .single()\r\n    .executeAndGetSingle\u003cMessage\u003e()\r\n\r\nprintln(message.content)\r\n```\r\n\r\nYou can also use this function to convert your data to a Map, rather than a separate DTO.\r\n\r\n```kotlin\r\nval message = postgresClient.from\u003cMessage\u003e(\"messages\")\r\n    .select()\r\n    .eq(Message::id, 123L)\r\n    .limit(1)\r\n    .single()\r\n    .executeAndGetSingle\u003cMap\u003cString, Any\u003e\u003e()\r\n\r\nprintln(message[\"content\"])\r\n```\r\n\r\n#### executeAndGetList\u003cT\u003e\r\n\r\nThe `executeAndGetList\u003cT\u003e` function is pretty much the same as the `executeAndGetSingle\u003cT\u003e` function, however,\r\nthis functions returns a list of `T`.\r\n\r\n```kotlin\r\nval messages = postgresClient.from\u003cAny\u003e(\"messages\")\r\n    .select()\r\n    .executeAndGetList\u003cMessage\u003e()\r\n\r\nmessages.forEach { message -\u003e\r\n    println(messege.content)\r\n}\r\n```\r\n\r\n### CRUD\r\n\r\n#### Selecting data\r\n\r\nThe `select` function is used for selecting data.\r\n\r\n```kotlin\r\nval response = postgresClient.from\u003cAny\u003e(\"messages\")\r\n    .select(count = Count.EXACT) // will allow accessing data AND count\r\n    .eq(\"content\", \"foobar\")\r\n    .execute()\r\n```\r\n\r\n#### Inserting data\r\n\r\nThe `insert` function is used for inserting or upserting data.\r\n\r\n```kotlin\r\nval message = Message(\r\n    id = 123L,\r\n    content = \"foobar\"\r\n)\r\n\r\nval response = postgresClient.from\u003cMessage\u003e(\"messages\")\r\n    .insert(message)\r\n    .execute()\r\n\r\nval response = postgresClient.from\u003cAny\u003e(\"messages\")\r\n    .insert(\r\n        value = mapOf(\"id\" to 123L, \"content\" to \"foobar\"),\r\n        upsert = true\r\n    )\r\n```\r\n\r\n#### Updating data\r\n\r\nThe `update` function is used for updating data.\r\n\r\n```kotlin\r\nval response = postgresClient.from\u003cAny\u003e(\"messages\")\r\n    .update(mapOf(\"content\" to \"hello\"))\r\n    .eq(\"id\", 123L)\r\n    .execute()\r\n```\r\n\r\n#### Deleting data\r\n\r\nThe `delete` function is used for deleting data.\r\n\r\n```kotlin\r\nval response = postgresClient.from\u003cAny\u003e(\"messages\")\r\n    .delete()\r\n    .eq(\"id\", 123L)\r\n    .execute()\r\n```\r\n\r\n## HTTP / (De)-Serialization\r\n\r\nThe Apache Http-Client (5.x) is used for executing HTTP calls, Jackson is used to convert responses to DTOs.\r\n\r\nIf you want to change that, you need to implement the `PostgrestHttpClient` and the `PostgrestJsonConverter` interface.\r\n\r\nSee [PostgrestHttpClientApache](src/main/kotlin/io/supabase/postgrest/http/PostgrestHttpClientApache.kt) and [PostgrestsonConverterJackson](src/main/kotlin/io/supabase/postgrest/json/PostgrestJsonConverterJackson.kt).\r\n\r\n```kotlin\r\nval postgrestClient = PostgrestClient(\r\n    httpClient = customHttpClient(),\r\n    jsonConverter = customConverter()\r\n)\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase-community%2Fpostgrest-kt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupabase-community%2Fpostgrest-kt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase-community%2Fpostgrest-kt/lists"}