mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-21 09:01:32 +00:00
rename sqlite_call_wrapper to sqlite_call
This commit is contained in:
@ -2,14 +2,14 @@ use std::str::FromStr;
|
||||
|
||||
use crate::errors::err_msg;
|
||||
use crate::errors::AppResult;
|
||||
use crate::utils::sqlite_call_wrapper;
|
||||
use crate::utils::sqlite_call;
|
||||
|
||||
pub fn create_scheme() -> AppResult<()> {
|
||||
sqlite_call_wrapper("CREATE TABLE messages(message text, username text)").map(drop)
|
||||
sqlite_call("CREATE TABLE messages(message text, username text)").map(drop)
|
||||
}
|
||||
|
||||
pub fn add_post(message: String, username: String) -> AppResult<()> {
|
||||
sqlite_call_wrapper(
|
||||
sqlite_call(
|
||||
format!(
|
||||
r#"INSERT INTO messages VALUES("{}","{}")"#,
|
||||
message, username
|
||||
@ -20,7 +20,7 @@ pub fn add_post(message: String, username: String) -> AppResult<()> {
|
||||
}
|
||||
|
||||
pub fn get_all_posts() -> AppResult<String> {
|
||||
sqlite_call_wrapper(
|
||||
sqlite_call(
|
||||
"SELECT json_group_array(
|
||||
json_object('message', message, 'username', username)
|
||||
) AS json_result FROM (SELECT * FROM messages)",
|
||||
@ -28,7 +28,7 @@ pub fn get_all_posts() -> AppResult<String> {
|
||||
}
|
||||
|
||||
pub fn get_posts_by_username(username: String) -> AppResult<String> {
|
||||
sqlite_call_wrapper(
|
||||
sqlite_call(
|
||||
format!(
|
||||
"SELECT json_group_array(
|
||||
json_object('message', message, 'username', username)
|
||||
@ -40,7 +40,7 @@ pub fn get_posts_by_username(username: String) -> AppResult<String> {
|
||||
}
|
||||
|
||||
pub fn get_posts_count() -> AppResult<i32> {
|
||||
let result = sqlite_call_wrapper("SELECT COUNT(*) from messages")?;
|
||||
let result = sqlite_call("SELECT COUNT(*) from messages")?;
|
||||
|
||||
i32::from_str(result.as_str()).map_err(|e| {
|
||||
err_msg(&format!(
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::errors::{err_msg, AppResult};
|
||||
use crate::sqlite;
|
||||
|
||||
pub fn sqlite_call_wrapper(bytes: &str) -> AppResult<String> {
|
||||
pub fn sqlite_call(bytes: &str) -> AppResult<String> {
|
||||
let response = sqlite::call(bytes.as_bytes());
|
||||
|
||||
// Decode query result to a utf8 string
|
||||
|
Reference in New Issue
Block a user