Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Option fields #61

Closed
chrissuozzo opened this issue Dec 1, 2023 · 1 comment · Fixed by #62
Closed

feat: add support for Option fields #61

chrissuozzo opened this issue Dec 1, 2023 · 1 comment · Fixed by #62

Comments

@chrissuozzo
Copy link
Contributor

The proposed feature would allow nullable column values to be represented as Option fields within a user's row structure. For example, if you have this table with the nullable column optional_value:

CREATE TABLE sometable (
  id INTEGER NOT NULL,
  value, TEXT NOT NULL,
  optional_value INTEGER,
  PRIMARY KEY (id)
);

You could then represent the row as:

#[derive(Debug, serde::Deserialize)]
struct SomeTableRow {
  id: i64,
  value: String,
  optional_value: Option<i64>,
}

The following query would then work as expected:

let rows = db
     .execute("SELECT * FROM sometable")
     .await?
     .rows
     .iter()
     .map(de::from_row)
     .collect::<Result<Vec<SomeTableRow>, _>>()?;

Currently, the above query will result in a runtime error if any row has a value set in the optional_value column:

Error: invalid type: integer `1701384211`, expected option
error: process didn't exit successfully: `target\debug\test.exe` (exit code: 1)
@chrissuozzo
Copy link
Contributor Author

This should do it: #62

@psarna psarna closed this as completed in #62 Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant