pass db json back as bytes

This commit is contained in:
Damien Elmes 2020-06-12 20:20:29 +10:00
parent 2845941a28
commit cf6d4f1cb9
3 changed files with 5 additions and 5 deletions

View file

@ -67,7 +67,7 @@ impl FromSql for SqlValue {
}
}
pub(super) fn db_command_bytes(ctx: &SqliteStorage, input: &[u8]) -> Result<String> {
pub(super) fn db_command_bytes(ctx: &SqliteStorage, input: &[u8]) -> Result<Vec<u8>> {
let req: DBRequest = serde_json::from_slice(input)?;
let resp = match req {
DBRequest::Query {
@ -95,7 +95,7 @@ pub(super) fn db_command_bytes(ctx: &SqliteStorage, input: &[u8]) -> Result<Stri
}
DBRequest::ExecuteMany { sql, args } => db_execute_many(ctx, &sql, &args)?,
};
Ok(serde_json::to_string(&resp)?)
Ok(serde_json::to_vec(&resp)?)
}
pub(super) fn db_query_row(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Result<DBResult> {

View file

@ -1525,7 +1525,7 @@ impl Backend {
}
}
pub fn db_command(&self, input: &[u8]) -> Result<String> {
pub fn db_command(&self, input: &[u8]) -> Result<Vec<u8>> {
self.with_col(|col| db_command_bytes(&col.storage, input))
}
}

View file

@ -147,8 +147,8 @@ impl Backend {
.db_command(in_bytes)
.map_err(|e| DBError::py_err(e.localized_description(&self.backend.i18n())))
});
let out_string = out_res?;
let out_obj = PyBytes::new(py, out_string.as_bytes());
let out_bytes = out_res?;
let out_obj = PyBytes::new(py, &out_bytes);
Ok(out_obj.into())
}
}