{"id":13753813,"url":"https://github.com/Dowwie/tokio-postgres-mapper","last_synced_at":"2025-05-09T21:35:55.056Z","repository":{"id":47436237,"uuid":"233038910","full_name":"Dowwie/tokio-postgres-mapper","owner":"Dowwie","description":"Proc-macro library used to map a tokio-postgres row to a Rust type (struct)","archived":false,"fork":false,"pushed_at":"2022-07-20T21:01:59.000Z","size":48,"stargazers_count":64,"open_issues_count":4,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-11T22:22:50.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dowwie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-10T12:05:20.000Z","updated_at":"2024-10-17T20:51:46.000Z","dependencies_parsed_at":"2022-09-26T20:40:46.132Z","dependency_job_id":null,"html_url":"https://github.com/Dowwie/tokio-postgres-mapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dowwie%2Ftokio-postgres-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dowwie%2Ftokio-postgres-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dowwie%2Ftokio-postgres-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dowwie%2Ftokio-postgres-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dowwie","download_url":"https://codeload.github.com/Dowwie/tokio-postgres-mapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224884615,"owners_count":17386121,"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":[],"created_at":"2024-08-03T09:01:30.139Z","updated_at":"2024-11-16T06:30:50.217Z","avatar_url":"https://github.com/Dowwie.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# tokio-pg-mapper\n\n`tokio_postgres-mapper` is a proc-macro designed to make mapping from postgresql\ntables to structs simple.\n\n### Why?\n\nIt can be frustrating to write a lot of boilerplate and, ultimately, duplicated\ncode for mapping from postgres Rows into structs.\n\nFor example, this might be what someone would normally write:\n\n```rust\nextern crate postgres;\n\nuse postgres::rows::Row;\n\npub struct User {\n    pub id: i64,\n    pub name: String,\n    pub email: Option\u003cString\u003e,\n}\n\nimpl From\u003cRow\u003e for User {\n    fn from(row: Row) -\u003e Self {\n        Self {\n            id: row.get(\"id\"),\n            name: row.get(\"name\"),\n            email: row.get(\"email\"),\n        }\n    }\n}\n\n// code to execute a query here and get back a row\nlet user = User::from(row); // this can panic\n```\n\nThis becomes worse when manually implementating using the non-panicking\n`get_opt` method variant.\n\nUsing this crate, the boilerplate is removed, and panicking and non-panicking\nimplementations are derived:\n\n```rust\nextern crate tokio_pg_mapper_derive;\nextern crate tokio_pg_mapper;\n\nuse tokio_pg_mapper::FromTokioPostgresRow;\nuse tokio_pg_mapper_derive::PostgresMapper;\n\n#[derive(PostgresMapper)]\npub struct User {\n    pub id: i64,\n    pub name: String,\n    pub email: Option\u003cString\u003e,\n}\n\n// Code to execute a query here and get back a row might now look like:\nlet stmt = \"SELECT * FROM user WHERE username = $1 AND password = $2\";\n\nlet result = client.query_one(stmt, \u0026[\u00265, \"asdf\"]).await?;\nlet user = User::from_row(result).unwrap(); // or from_row_ref(\u0026result)\n\n\n```\n\n\n### The two crates\n\nThis repository contains two crates: `postgres-mapper` which contains an `Error`\nenum and traits for converting from a `tokio-postgres` `Row`\nwithout panicking, and `postgres-mapper-derive` which contains the proc-macro.\n\n\n### Installation\n\nInstall `tokio-pg-mapper-derive` and `tokio-pg-mapper` from crates.io\n\n\n### License\n\nISC.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDowwie%2Ftokio-postgres-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDowwie%2Ftokio-postgres-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDowwie%2Ftokio-postgres-mapper/lists"}