{"id":16980967,"url":"https://github.com/guzba/waterpark","last_synced_at":"2025-03-23T17:31:05.952Z","repository":{"id":64686945,"uuid":"573560448","full_name":"guzba/waterpark","owner":"guzba","description":"Thread-safe pools. Great for database connections in a multithreaded HTTP server.","archived":false,"fork":false,"pushed_at":"2024-02-11T06:38:15.000Z","size":115,"stargazers_count":29,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-18T22:24:02.874Z","etag":null,"topics":["connection-pool","multithreading","mysql","nim","postgres","postgresql","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/guzba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2022-12-02T19:02:02.000Z","updated_at":"2025-03-04T23:15:57.000Z","dependencies_parsed_at":"2023-02-16T10:30:25.967Z","dependency_job_id":"64c1207a-5649-4af3-a6a1-0d823f087353","html_url":"https://github.com/guzba/waterpark","commit_stats":{"total_commits":47,"total_committers":5,"mean_commits":9.4,"dds":"0.17021276595744683","last_synced_commit":"71a579673f987e72354d33d4fba9e5e2c2f1ff66"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":"treeform/nimtemplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fwaterpark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fwaterpark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fwaterpark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fwaterpark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guzba","download_url":"https://codeload.github.com/guzba/waterpark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245140876,"owners_count":20567461,"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":["connection-pool","multithreading","mysql","nim","postgres","postgresql","sqlite"],"created_at":"2024-10-14T02:04:16.256Z","updated_at":"2025-03-23T17:31:05.641Z","avatar_url":"https://github.com/guzba.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Waterpark\n\n`nimble install waterpark`\n\n![Github Actions](https://github.com/guzba/waterpark/workflows/Github%20Actions/badge.svg)\n\n[API reference](https://guzba.github.io/waterpark/)\n\nWaterpark provides thread-safe object pools and a generic `Pool[T]` to create your own.\n\nCurrently there are 3 built-in pools:\n\n* `import waterpark/postgres`\n* `import waterpark/mysql`\n* `import waterpark/sqlite`\n\nAdding more pools is planned, including for Redis etc.\n\nA great use-case for these thread-safe pools is for database connections when running\na multithreaded HTTP server like [Mummy](https://github.com/guzba/mummy).\n\nUsing Waterpark connection pools for multiple different databases is no problem. You can create one or more pools for each database without any trouble. See [this example](https://github.com/guzba/waterpark/blob/master/examples/mummy_sqlite.nim) to get an idea of how this works.\n\n## Example\n\nThe following example shows a Postgres database connection pool being used in a Mummy HTTP request handler.\n\n```nim\nimport mummy, mummy/routers, waterpark/postgres, std/strutils\n\nlet pg = newPostgresPool(3, \"localhost\", \"pguser\", \"dietcoke\", \"test\")\n\nproc indexHandler(request: Request) =\n  var count: int\n\n  pg.withConnection conn:\n    count = parseInt(conn.getValue(sql\"select count from table1 limit 1\"))\n\n  # ^ This is shorthand for:\n  # let conn = pg.borrow() # Take a Postgres connection from the pool\n  # try:\n  #   count = parseInt(conn.getValue(sql\"select count from table1 limit 1\"))\n  # finally:\n  #   pg.recycle(conn) # Return the Postgres connection to the pool\n\n  var headers: HttpHeaders\n  headers[\"Content-Type\"] = \"text/plain\"\n  request.respond(200, headers, \"Count: \" \u0026 $count \u0026 \"\\n\")\n\nvar router: Router\nrouter.get(\"/\", indexHandler)\n\nlet server = newServer(router)\necho \"Serving on http://localhost:8080\"\nserver.serve(Port(8080))\n```\n\nThere are more examples in the [examples/](https://github.com/guzba/waterpark/tree/master/examples) directory of this repo.\n\n## Tips\n\n* When a new connection pool is created for Postgres, MySQL, SQLite etc, a size for the pool is given. That number of database connections is opened immediately. If this does not succeed, an exception is raised so you know right away. This ensures you know your server can talk to your database long before you begin listening for incoming requests.\n\n* When a thread wants to borrow from a pool, either that thread will receive a connection from the pool of available connections immediately or it will block until a connection is available. This means you don't need to worry about something causing runaway connections to be opened, potentially taking down your database server.\n\n## Testing\n\n`nimble test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzba%2Fwaterpark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguzba%2Fwaterpark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzba%2Fwaterpark/lists"}