{"id":21010907,"url":"https://github.com/hfhbd/postgres-native-sqldelight","last_synced_at":"2025-10-25T14:34:55.873Z","repository":{"id":37072789,"uuid":"491982242","full_name":"hfhbd/postgres-native-sqldelight","owner":"hfhbd","description":"A Kotlin native Postgres driver for SqlDelight.","archived":false,"fork":false,"pushed_at":"2024-10-16T06:34:32.000Z","size":687,"stargazers_count":36,"open_issues_count":6,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-17T23:08:17.867Z","etag":null,"topics":["kotlin-native","postgresql","sqldelight"],"latest_commit_sha":null,"homepage":"https://postgresnative.softwork.app/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hfhbd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"hfhbd"}},"created_at":"2022-05-13T17:17:04.000Z","updated_at":"2024-10-16T06:34:34.000Z","dependencies_parsed_at":"2023-10-01T16:26:56.190Z","dependency_job_id":"db4890a3-b24e-47f8-bd70-419e0aa6c45a","html_url":"https://github.com/hfhbd/postgres-native-sqldelight","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Fpostgres-native-sqldelight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Fpostgres-native-sqldelight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Fpostgres-native-sqldelight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Fpostgres-native-sqldelight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hfhbd","download_url":"https://codeload.github.com/hfhbd/postgres-native-sqldelight/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225325412,"owners_count":17456713,"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":["kotlin-native","postgresql","sqldelight"],"created_at":"2024-11-19T09:24:26.284Z","updated_at":"2025-10-25T14:34:55.799Z","avatar_url":"https://github.com/hfhbd.png","language":"Kotlin","funding_links":["https://github.com/sponsors/hfhbd"],"categories":[],"sub_categories":[],"readme":"# PostgreSQL native SQLDelight driver\n\nA native Postgres driver using libpq.\n\nYou can use the driver with [SQLDelight](https://github.com/cashapp/sqldelight), but this is not required.\n\n- [Source code](https://github.com/hfhbd/postgres-native-sqldelight)\n\n\u003e Keep in mind, until now, this is only a single-threaded wrapper over libpq using 1 connection only. There is no\n\u003e connection pool nor multithread support (like JDBC or R2DBC).\n\n## Install\n\nYou need `libpq` installed and available in your `$PATH`.\n\nThis package is uploaded to MavenCentral and supports macOS and linuxX64.\nWindows is currently not supported.\n\n````kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"app.softwork:postgres-native-sqldelight-driver:LATEST\")\n}\n\n// optional SQLDelight setup:\nsqldelight {\n    databases.register(\"NativePostgres\") {\n        dialect(\"app.softwork:postgres-native-sqldelight-dialect:LATEST\")\n    }\n    linkSqlite.set(false)\n}\n````\n\n## Usage\n\n```kotlin\nval driver = PostgresNativeDriver(\n    host = \"localhost\",\n    port = 5432,\n    user = \"postgres\",\n    database = \"postgres\",\n    password = \"password\",\n    options = null,\n    listenerSupport = ListenerSupport.Remote(coroutineScope)\n)\n```\n\n### Listeners\n\nThis driver supports local and remote listeners.\nLocal listeners only notify this client, ideally for testing or using the database with only one client at a time.\nRemote listener support uses `NOTIFY` and `LISTEN`, so you can use this to sync multiple clients or with existing\ndatabase\ntriggers.\nSQLDelight uses and expects the table name as payload, but you can provide a mapper function.\n\n### SQLDelight Support\n\nJust create the driver and use your database instances in the usual way.\n\n### Raw usage\n\nBeside SQLDelight you could also use this driver with raw queries.\nThe identifier is used to reuse prepared statements.\n\n```kotlin\ndriver.execute(identifier = null, sql = \"INSERT INTO foo VALUES (42)\", parameters = 0, binders = null)\n```\n\nIt also supports a real lazy cursor by using a `Flow`. The `fetchSize` parameter defines how many rows are fetched at\nonce:\n\n```kotlin\nval namesFlow: Flow\u003cSimple\u003e = driver.executeQueryAsFlow(\n    identifier = null,\n    sql = \"SELECT index, name, bytes FROM foo\",\n    mapper = { cursor -\u003e\n        Simple(\n            index = cursor.getLong(0)!!.toInt(),\n            name = cursor.getString(1),\n            byteArray = cursor.getBytes(2)\n        )\n    },\n    parameters = 0,\n    fetchSize = 100,\n    binders = null\n)\n```\n\nAnd for bulk imports, use the `copy` method. You need to enable `COPY` first:\n\n```kotlin\ndriver.execute(514394779, \"COPY foo FROM STDIN (FORMAT CSV)\", 0)\nval rows = driver.copy(\"1,2,3\\n4,5,6\\n\")\n```\n\n## License\n\nApache 2\n\n## Contributing\n\n### Devcontainers\n\nStart the devcontainer, that's it.\n\n### Local\n\n#### docker compose\n\nThis is the preferred local option. The `app` service contains the JVM as well as libpq.\n\n#### Manual\n\nYou need to install `libpq`, eg using Homebrew: https://formulae.brew.sh/formula/libpq#default\n\nFor installation using homebrew, the default path is already added.\n\nOtherwise, you have to add the compiler flags to\nthe [libpq.def](postgres-native-sqldelight-driver/src/nativeInterop/cinterop/libpq.def).\nThe exact flags depend on your config, for example:\n\n```\nFor compilers to find libpq you may need to set:\n  export LDFLAGS=\"-L/home/linuxbrew/.linuxbrew/opt/libpq/lib\"\n  export CPPFLAGS=\"-I/home/linuxbrew/.linuxbrew/opt/libpq/include\"\n```\n\n##### Testing\n\nIf you installed libpq with homebrew, it will install the platform-specific artifact.\n\nTo test other platforms, eg. linux x64 on macOS, you need to install the platform-specific libpq of linux x64 too.\n\nTo start the postgres instance, you can use docker:\n\n```sh\ndocker run -e POSTGRES_PASSWORD=password -p 5432:5432 postgres\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhfhbd%2Fpostgres-native-sqldelight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhfhbd%2Fpostgres-native-sqldelight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhfhbd%2Fpostgres-native-sqldelight/lists"}