{"id":13468229,"url":"https://github.com/vapor/postgres-kit","last_synced_at":"2025-04-08T01:36:56.956Z","repository":{"id":38296524,"uuid":"117408032","full_name":"vapor/postgres-kit","owner":"vapor","description":"🐘 Non-blocking, event-driven Swift client for PostgreSQL.","archived":false,"fork":false,"pushed_at":"2025-03-18T17:59:44.000Z","size":829,"stargazers_count":196,"open_issues_count":7,"forks_count":71,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-03-31T15:08:15.710Z","etag":null,"topics":["async","postgresql","server-side-swift","sql","swift","vapor","vapor-service"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vapor.png","metadata":{"funding":{"github":["vapor"],"open_collective":"vapor"},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-14T06:33:00.000Z","updated_at":"2025-03-20T05:02:36.000Z","dependencies_parsed_at":"2023-11-11T17:33:20.053Z","dependency_job_id":"5a004ba1-1c43-4267-8b21-75cf91557390","html_url":"https://github.com/vapor/postgres-kit","commit_stats":{"total_commits":396,"total_committers":45,"mean_commits":8.8,"dds":"0.38636363636363635","last_synced_commit":"99d09c4b064c62f6f0143017f9195a6836c58f3f"},"previous_names":["vapor/postgresql"],"tags_count":102,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fpostgres-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fpostgres-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fpostgres-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fpostgres-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vapor","download_url":"https://codeload.github.com/vapor/postgres-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247761051,"owners_count":20991531,"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":["async","postgresql","server-side-swift","sql","swift","vapor","vapor-service"],"created_at":"2024-07-31T15:01:07.378Z","updated_at":"2025-04-08T01:36:56.941Z","avatar_url":"https://github.com/vapor.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/vapor/postgres-kit/assets/1130717/02ca33b1-d788-4846-8280-7cd89f09c397\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://github.com/vapor/postgres-kit/assets/1130717/91de055b-0e4f-42f3-8257-946ac40d731c\"\u003e\n  \u003cimg src=\"https://github.com/vapor/postgres-kit/assets/1130717/91de055b-0e4f-42f3-8257-946ac40d731c\" height=\"96\" alt=\"PostgresKit\"\u003e\n\u003c/picture\u003e \n\u003cbr\u003e\n\u003cbr\u003e\n\u003ca href=\"https://docs.vapor.codes/4.0/\"\u003e\u003cimg src=\"https://design.vapor.codes/images/readthedocs.svg\" alt=\"Documentation\"\u003e\u003c/a\u003e\n\u003ca href=\"https://discord.gg/vapor\"\u003e\u003cimg src=\"https://design.vapor.codes/images/discordchat.svg\" alt=\"Team Chat\"\u003e\u003c/a\u003e\n\u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://design.vapor.codes/images/mitlicense.svg\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/vapor/postgres-kit/actions/workflows/test.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/vapor/postgres-kit/test.yml?event=push\u0026style=plastic\u0026logo=github\u0026label=tests\u0026logoColor=%23ccc\" alt=\"Continuous Integration\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/github/vapor/postgres-kit\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/vapor/postgres-kit?style=plastic\u0026logo=codecov\u0026label=codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"https://swift.org\"\u003e\u003cimg src=\"https://design.vapor.codes/images/swift59up.svg\" alt=\"Swift 5.9+\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n🐘 Non-blocking, event-driven Swift client for PostgreSQL.\n\n### Usage\n\nUse the SPM string to easily include the dependendency in your `Package.swift` file.\n\n```swift\n.package(url: \"https://github.com/vapor/postgres-kit.git\", from: \"2.0.0\")\n```\n\n### Supported Platforms\n\nPostgresKit supports the following platforms:\n\n- Ubuntu 20.04+\n- macOS 10.15+\n\n## Overview\n\nPostgresKit is an [SQLKit] driver for PostgreSQL clients. It supports building and serializing Postgres-dialect SQL queries. PostgresKit uses [PostgresNIO] to connect and communicate with the database server asynchronously. [AsyncKit](https://github.com/vapor/async-kit) is used to provide connection pooling.\n\n\u003e [!IMPORTANT]\n\u003e It is strongly recommended that users who leverage PostgresKit directly (e.g. absent the Fluent ORM layer) take advantage of PostgresNIO's [PostgresClient] API for connection management rather than relying upon the legacy AsyncKit API.\n\n[SQLKit]: https://github.com/vapor/sql-kit\n[PostgresNIO]: https://github.com/vapor/postgres-nio\n[AsyncKit]: https://github.com/vapor/async-kit\n[PostgresClient]: https://api.vapor.codes/postgresnio/documentation/postgresnio/postgresclient \n\n### Configuration\n\nDatabase connection options and credentials are specified using a `PostgresConfiguration` struct. \n\n```swift\nimport PostgresKit\n\nlet configuration = PostgresConfiguration(\n    hostname: \"localhost\",\n    username: \"vapor_username\",\n    password: \"vapor_password\",\n    database: \"vapor_database\"\n)\n```\n\nURL string based configuration is also supported.\n\n```swift\nguard let configuration = PostgresConfiguration(url: \"postgres://...\") else {\n    ...\n}\n```\n\nTo connect via unix-domain sockets, use `unixDomainSocketPath` instead of `hostname` and `port`.\n\n```swift\nlet configuration = PostgresConfiguration(\n    unixDomainSocketPath: \"/path/to/socket\",\n    username: \"vapor_username\",\n    password: \"vapor_password\",\n    database: \"vapor_database\"\n)\n```\n\n### Connection Pool\n\nOnce you have a `PostgresConfiguration`, you can use it to create a connection source and pool.\n\n```swift\nlet eventLoopGroup: EventLoopGroup = ...\ndefer { try! eventLoopGroup.syncShutdown() }\n\nlet pools = EventLoopGroupConnectionPool(\n    source: PostgresConnectionSource(configuration: configuration), \n    on: eventLoopGroup\n)\ndefer { pools.shutdown() }\n```\n\nFirst create a `PostgresConnectionSource` using the configuration struct. This type is responsible for creating new connections to your database server as needed.\n\nNext, use the connection source to create an `EventLoopGroupConnectionPool`. You will also need to pass an `EventLoopGroup`. For more information on creating an `EventLoopGroup`, visit SwiftNIO's [documentation](https://apple.github.io/swift-nio/docs/current/NIO/index.html). Make sure to shutdown the connection pool before it deinitializes. \n\n`EventLoopGroupConnectionPool` is a collection of pools for each event loop. When using `EventLoopGroupConnectionPool` directly, random event loops will be chosen as needed.\n\n```swift\npools.withConnection { conn \n    print(conn) // PostgresConnection on randomly chosen event loop\n}\n```\n\nTo get a pool for a specific event loop, use `pool(for:)`. This returns an `EventLoopConnectionPool`. \n\n```swift\nlet eventLoop: EventLoop = ...\nlet pool = pools.pool(for: eventLoop)\n\npool.withConnection { conn\n    print(conn) // PostgresConnection on eventLoop\n}\n```\n\n### PostgresDatabase\n\nBoth `EventLoopGroupConnectionPool` and `EventLoopConnectionPool` can be used to create instances of `PostgresDatabase`.\n\n```swift\nlet postgres = pool.database(logger: ...) // PostgresDatabase\nlet rows = try postgres.simpleQuery(\"SELECT version();\").wait()\n```\n\nVisit [PostgresNIO's docs](https://github.com/vapor/postgres-nio) for more information on using `PostgresDatabase`.\n\n### SQLDatabase\n\nA `PostgresDatabase` can be used to create an instance of `SQLDatabase`.\n\n```swift\nlet sql = postgres.sql() // SQLDatabase\nlet planets = try sql.select().column(\"*\").from(\"planets\").all().wait()\n```\n\nVisit [SQLKit's docs](https://github.com/vapor/sql-kit) for more information on using `SQLDatabase`. \n","funding_links":["https://github.com/sponsors/vapor","https://opencollective.com/vapor"],"categories":["Swift","HarmonyOS"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvapor%2Fpostgres-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvapor%2Fpostgres-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvapor%2Fpostgres-kit/lists"}