mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-24 18:41:32 +00:00
Renamings
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
use crate::errors::{err_msg, AppResult};
|
||||
use crate::sqlite;
|
||||
|
||||
pub fn sqlite_call(bytes: &str) -> AppResult<String> {
|
||||
let response = sqlite::call(bytes.as_bytes());
|
||||
pub fn query(query: &str) -> AppResult<String> {
|
||||
let response = sqlite::call(query.as_bytes());
|
||||
|
||||
// Decode query result to a utf8 string
|
||||
let result_str = std::str::from_utf8(&response);
|
||||
@ -17,7 +17,7 @@ pub fn sqlite_call(bytes: &str) -> AppResult<String> {
|
||||
.map_err(|e| {
|
||||
err_msg(&format!(
|
||||
"unable to decode result from bytes {:#x?}: {}",
|
||||
bytes, e
|
||||
query, e
|
||||
))
|
||||
})
|
||||
.map(|s| s.to_string())
|
@ -8,9 +8,9 @@ use crate::errors::err_msg;
|
||||
use crate::errors::AppResult;
|
||||
|
||||
pub mod api;
|
||||
pub mod database;
|
||||
pub mod errors;
|
||||
pub mod model;
|
||||
pub mod utils;
|
||||
|
||||
fn init() {
|
||||
logger::WasmLogger::init_with_level(log::Level::Info).unwrap();
|
||||
|
@ -1,15 +1,15 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::database;
|
||||
use crate::errors::err_msg;
|
||||
use crate::errors::AppResult;
|
||||
use crate::utils::sqlite_call;
|
||||
|
||||
pub fn create_scheme() -> AppResult<()> {
|
||||
sqlite_call("CREATE TABLE messages(message text, username text)").map(drop)
|
||||
database::query("CREATE TABLE messages(message text, username text)").map(drop)
|
||||
}
|
||||
|
||||
pub fn add_post(message: String, username: String) -> AppResult<()> {
|
||||
sqlite_call(
|
||||
database::query(
|
||||
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(
|
||||
database::query(
|
||||
"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(
|
||||
database::query(
|
||||
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("SELECT COUNT(*) from messages")?;
|
||||
let result = database::query("SELECT COUNT(*) from messages")?;
|
||||
|
||||
i32::from_str(result.as_str()).map_err(|e| {
|
||||
err_msg(&format!(
|
||||
|
Reference in New Issue
Block a user