diff options
author | Teddy Wing | 2022-03-16 00:43:39 +0100 |
---|---|---|
committer | Teddy Wing | 2022-03-16 00:43:39 +0100 |
commit | 99bcc93dc2b1245fb977cb4d04b479652c13f9ac (patch) | |
tree | d8c9b09844a222ea8552962ee5880db8e1a5c43f /src/yaml/sql.rs | |
parent | daaab78f45dee52e6950e21cfd4b653cff778a11 (diff) | |
download | yaqlite-99bcc93dc2b1245fb977cb4d04b479652c13f9ac.tar.bz2 |
select(): Trying to convert a SQLite row to `yaml_rust::Yaml`
Still a work in progress. Trying to figure out what makes the most sense
for converting between the different types in SQLite and YAML.
This code still has some compilation errors.
Diffstat (limited to 'src/yaml/sql.rs')
-rw-r--r-- | src/yaml/sql.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/yaml/sql.rs b/src/yaml/sql.rs index 68488d2..d065718 100644 --- a/src/yaml/sql.rs +++ b/src/yaml/sql.rs @@ -34,3 +34,30 @@ impl<'a> rusqlite::ToSql for Yaml<'a> { Ok(sql_output) } } + +impl<'a> rusqlite::types::FromSql for Yaml<'a> { + fn column_result( + value: rusqlite::types::ValueRef<'_>, + ) -> rusqlite::types::FromSqlResult<Self> { + use rusqlite::types::ValueRef; + + match value { + ValueRef::Integer(i) => Ok(Yaml(&yaml_rust::Yaml::Integer(i))), + ValueRef::Real(f) => + Ok(Yaml(&yaml_rust::Yaml::Real(f.to_string()))), + ValueRef::Text(_) => { + let s = value.as_str()?; + + Ok(Yaml(&yaml_rust::Yaml::String(s.to_owned()))) + } + ValueRef::Blob(_) => { + // TODO: How should we handle blobs? Parsing as string might not + // make the most sense. + let b = value.as_str()?; + + Ok(Yaml(&yaml_rust::Yaml::String(b.to_owned()))) + } + ValueRef::Null => Ok(Yaml(&yaml_rust::Yaml::Null)), + } + } +} |