mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-22 17:41:32 +00:00
msg => message
This commit is contained in:
@ -11,7 +11,7 @@ export function handler(input: string): string {
|
|||||||
|
|
||||||
if (request.action == Action.Post) {
|
if (request.action == Action.Post) {
|
||||||
let post = request as PostRequest;
|
let post = request as PostRequest;
|
||||||
addMessage(post.msg, post.username);
|
addMessage(post.message, post.username);
|
||||||
let count = getPostsCount();
|
let count = getPostsCount();
|
||||||
|
|
||||||
let response = new PostResponse(count);
|
let response = new PostResponse(count);
|
||||||
|
@ -3,7 +3,7 @@ import {log} from "../node_modules/assemblyscript-sdk/assembly/logger";
|
|||||||
export function createScheme(): void {
|
export function createScheme(): void {
|
||||||
log("create scheme");
|
log("create scheme");
|
||||||
}
|
}
|
||||||
export function addMessage(msg: string, username: string): void {
|
export function addMessage(message: string, username: string): void {
|
||||||
log("add message");
|
log("add message");
|
||||||
}
|
}
|
||||||
export function getMessages(username: string | null): string {
|
export function getMessages(username: string | null): string {
|
||||||
|
@ -13,12 +13,12 @@ export abstract class Request {
|
|||||||
|
|
||||||
export class PostRequest extends Request {
|
export class PostRequest extends Request {
|
||||||
|
|
||||||
public readonly msg: string;
|
public readonly message: string;
|
||||||
public readonly username: string;
|
public readonly username: string;
|
||||||
|
|
||||||
constructor(msg: string, username: string) {
|
constructor(message: string, username: string) {
|
||||||
super();
|
super();
|
||||||
this.msg = msg;
|
this.message = message;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.action = Action.Post;
|
this.action = Action.Post;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ export function decode(input: string): Request {
|
|||||||
if (action == "Fetch") {
|
if (action == "Fetch") {
|
||||||
request = new FetchRequest(jsonHandler.filter_handle);
|
request = new FetchRequest(jsonHandler.filter_handle);
|
||||||
} else if (action == "Post") {
|
} else if (action == "Post") {
|
||||||
request = new PostRequest(jsonHandler.msg, jsonHandler.username)
|
request = new PostRequest(jsonHandler.message, jsonHandler.username)
|
||||||
} else {
|
} else {
|
||||||
request = new UnknownRequest()
|
request = new UnknownRequest()
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ export function decode(input: string): Request {
|
|||||||
class RequestJSONEventsHandler extends JSONHandler {
|
class RequestJSONEventsHandler extends JSONHandler {
|
||||||
|
|
||||||
public action: string;
|
public action: string;
|
||||||
public msg: string;
|
public message: string;
|
||||||
public username: string;
|
public username: string;
|
||||||
public filter_handle: string | null;
|
public filter_handle: string | null;
|
||||||
|
|
||||||
@ -79,8 +79,8 @@ class RequestJSONEventsHandler extends JSONHandler {
|
|||||||
|
|
||||||
if (name == "action") {
|
if (name == "action") {
|
||||||
this.action = value;
|
this.action = value;
|
||||||
} else if (name == "msg") {
|
} else if (name == "message") {
|
||||||
this.msg = value;
|
this.message = value;
|
||||||
} else if (name == "username") {
|
} else if (name == "username") {
|
||||||
this.username = value;
|
this.username = value;
|
||||||
this.filter_handle = value;
|
this.filter_handle = value;
|
||||||
|
@ -8,11 +8,11 @@ export abstract class Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Message {
|
export class Message {
|
||||||
msg: string;
|
message: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
constructor(msg: string, username: string) {
|
constructor(message: string, username: string) {
|
||||||
this.msg = msg;
|
this.message = message;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ export class UnknownResponse extends Response {
|
|||||||
let encoder = new JSONEncoder();
|
let encoder = new JSONEncoder();
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("action", "Unknown");
|
encoder.setString("action", "Unknown");
|
||||||
encoder.setString("msg", "cannot username request");
|
encoder.setString("message", "cannot username request");
|
||||||
encoder.popObject();
|
encoder.popObject();
|
||||||
|
|
||||||
return encoder.toString();
|
return encoder.toString();
|
||||||
@ -34,17 +34,16 @@ export class UnknownResponse extends Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PostResponse extends Response {
|
export class PostResponse extends Response {
|
||||||
msgCount: u32;
|
count: u32;
|
||||||
constructor(msgCount: u32) {
|
constructor(count: u32) {
|
||||||
super();
|
super();
|
||||||
this.msgCount = msgCount;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(): string {
|
serialize(): string {
|
||||||
let encoder = new JSONEncoder();
|
let encoder = new JSONEncoder();
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("action", "Post");
|
encoder.setInteger("count", this.count);
|
||||||
encoder.setInteger("count", this.msgCount);
|
|
||||||
encoder.popObject();
|
encoder.popObject();
|
||||||
|
|
||||||
return encoder.toString();
|
return encoder.toString();
|
||||||
@ -62,12 +61,11 @@ export class FetchResponse extends Response {
|
|||||||
serialize(): string {
|
serialize(): string {
|
||||||
let encoder = new JSONEncoder();
|
let encoder = new JSONEncoder();
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("action", "Fetch");
|
|
||||||
encoder.pushArray("posts");
|
encoder.pushArray("posts");
|
||||||
for (let i = 0; i < this.posts.length; i++) {
|
for (let i = 0; i < this.posts.length; i++) {
|
||||||
let twit = this.posts[i];
|
let twit = this.posts[i];
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("msg", twit.msg);
|
encoder.setString("message", twit.message);
|
||||||
encoder.setString("username", twit.username);
|
encoder.setString("username", twit.username);
|
||||||
encoder.popObject();
|
encoder.popObject();
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ describe("example", () => {
|
|||||||
|
|
||||||
it("can log some values to the console", () => {
|
it("can log some values to the console", () => {
|
||||||
log<string>(handler('{"hi": "hi"}'));
|
log<string>(handler('{"hi": "hi"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "Hello, Fluence!", "username": "fluencer"}'));
|
log<string>(handler('{"action": "Post", "message": "Hello, Fluence!", "username": "fluencer"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "Hello, fluencer!", "username": "John Doe"}'));
|
log<string>(handler('{"action": "Post", "message": "Hello, fluencer!", "username": "John Doe"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "How is it going?", "username": "fluencer"}'));
|
log<string>(handler('{"action": "Post", "message": "How is it going?", "username": "fluencer"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "Excellent! Thanks!", "username": "John Doe"}'));
|
log<string>(handler('{"action": "Post", "message": "Excellent! Thanks!", "username": "John Doe"}'));
|
||||||
log<string>(handler('{"action": "Fetch"}'));
|
log<string>(handler('{"action": "Fetch"}'));
|
||||||
log<string>(handler('{"action": "Fetch", "filter_handle": "John Doe"}'));
|
log<string>(handler('{"action": "Fetch", "filter_handle": "John Doe"}'));
|
||||||
log<string>(handler('{"action": "Fetch", "filter_handle": "fluencer"}'));
|
log<string>(handler('{"action": "Fetch", "filter_handle": "fluencer"}'));
|
||||||
|
@ -4,7 +4,7 @@ import {query} from "../node_modules/db-connector/assembly/sqlite"
|
|||||||
// main handler for an application
|
// main handler for an application
|
||||||
export function handler(username: string): string {
|
export function handler(username: string): string {
|
||||||
// Create table for messages storage
|
// Create table for messages storage
|
||||||
query(`CREATE TABLE messages(msg text, username text)`);
|
query(`CREATE TABLE messages(message text, username text)`);
|
||||||
|
|
||||||
// Insert message 'Hello, username!' using `username` as author's username
|
// Insert message 'Hello, username!' using `username` as author's username
|
||||||
query(`INSERT INTO messages VALUES("Hello, username!","` + username + `")`);
|
query(`INSERT INTO messages VALUES("Hello, username!","` + username + `")`);
|
||||||
@ -16,7 +16,7 @@ export function handler(username: string): string {
|
|||||||
// Get all messages as JSON via SQLite's JSON extension
|
// Get all messages as JSON via SQLite's JSON extension
|
||||||
return query(
|
return query(
|
||||||
`SELECT json_group_array(
|
`SELECT json_group_array(
|
||||||
json_object('msg', msg, 'username', username)
|
json_object('message', message, 'username', username)
|
||||||
) AS json_result FROM (SELECT * FROM messages)`
|
) AS json_result FROM (SELECT * FROM messages)`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ describe("example", () => {
|
|||||||
|
|
||||||
it("can log some values to the console", () => {
|
it("can log some values to the console", () => {
|
||||||
log<string>(handler('{"hi": "hi"}'));
|
log<string>(handler('{"hi": "hi"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "Hello, Fluence!", "username": "fluencer"}'));
|
log<string>(handler('{"action": "Post", "message": "Hello, Fluence!", "username": "fluencer"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "Hello, fluencer!", "username": "John Doe"}'));
|
log<string>(handler('{"action": "Post", "message": "Hello, fluencer!", "username": "John Doe"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "How is it going?", "username": "fluencer"}'));
|
log<string>(handler('{"action": "Post", "message": "How is it going?", "username": "fluencer"}'));
|
||||||
log<string>(handler('{"action": "Post", "msg": "Excellent! Thanks!", "username": "John Doe"}'));
|
log<string>(handler('{"action": "Post", "message": "Excellent! Thanks!", "username": "John Doe"}'));
|
||||||
log<string>(handler('{"action": "Fetch"}'));
|
log<string>(handler('{"action": "Fetch"}'));
|
||||||
log<string>(handler('{"action": "Fetch", "filter_handle": "John Doe"}'));
|
log<string>(handler('{"action": "Fetch", "filter_handle": "John Doe"}'));
|
||||||
log<string>(handler('{"action": "Fetch", "filter_handle": "fluencer"}'));
|
log<string>(handler('{"action": "Fetch", "filter_handle": "fluencer"}'));
|
||||||
|
@ -11,7 +11,7 @@ export function handler(input: string): string {
|
|||||||
|
|
||||||
if (request.action == Action.Post) {
|
if (request.action == Action.Post) {
|
||||||
let post = request as PostRequest;
|
let post = request as PostRequest;
|
||||||
addMessage(post.msg, post.username);
|
addMessage(post.message, post.username);
|
||||||
let count = getPostsCount();
|
let count = getPostsCount();
|
||||||
|
|
||||||
let response = new PostResponse(count);
|
let response = new PostResponse(count);
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import {query} from "../node_modules/db-connector/assembly/sqlite"
|
import {query} from "../node_modules/db-connector/assembly/sqlite"
|
||||||
|
|
||||||
export function createScheme(): void {
|
export function createScheme(): void {
|
||||||
let request = `CREATE TABLE messages(msg text, username text)`;
|
let request = `CREATE TABLE messages(message text, username text)`;
|
||||||
query(request);
|
query(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addMessage(msg: string, username: string): void {
|
export function addMessage(message: string, username: string): void {
|
||||||
let request = `INSERT INTO messages VALUES("` + msg + `", "` + username + `")`;
|
let request = `INSERT INTO messages VALUES("` + message + `", "` + username + `")`;
|
||||||
query(request);
|
query(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,14 +15,14 @@ export function getMessages(username: string | null): string {
|
|||||||
|
|
||||||
let request =
|
let request =
|
||||||
`SELECT json_group_array(
|
`SELECT json_group_array(
|
||||||
json_object('msg', msg, 'username', username)
|
json_object('message', message, 'username', username)
|
||||||
) AS json_result FROM
|
) AS json_result FROM
|
||||||
(SELECT * FROM messages WHERE username = "` + username + `")`;
|
(SELECT * FROM messages WHERE username = "` + username + `")`;
|
||||||
return query(request);
|
return query(request);
|
||||||
} else {
|
} else {
|
||||||
let request =
|
let request =
|
||||||
`SELECT json_group_array(
|
`SELECT json_group_array(
|
||||||
json_object('msg', msg, 'username', username)
|
json_object('message', message, 'username', username)
|
||||||
) AS json_result FROM (SELECT * FROM messages)`;
|
) AS json_result FROM (SELECT * FROM messages)`;
|
||||||
return query(request);
|
return query(request);
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@ export abstract class Request {
|
|||||||
|
|
||||||
export class PostRequest extends Request {
|
export class PostRequest extends Request {
|
||||||
|
|
||||||
public readonly msg: string;
|
public readonly message: string;
|
||||||
public readonly username: string;
|
public readonly username: string;
|
||||||
|
|
||||||
constructor(msg: string, username: string) {
|
constructor(message: string, username: string) {
|
||||||
super();
|
super();
|
||||||
this.msg = msg;
|
this.message = message;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.action = Action.Post;
|
this.action = Action.Post;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ export function decode(input: string): Request {
|
|||||||
if (action == "Fetch") {
|
if (action == "Fetch") {
|
||||||
request = new FetchRequest(jsonHandler.filter_handle);
|
request = new FetchRequest(jsonHandler.filter_handle);
|
||||||
} else if (action == "Post") {
|
} else if (action == "Post") {
|
||||||
request = new PostRequest(jsonHandler.msg, jsonHandler.username)
|
request = new PostRequest(jsonHandler.message, jsonHandler.username)
|
||||||
} else {
|
} else {
|
||||||
request = new UnknownRequest()
|
request = new UnknownRequest()
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ export function decode(input: string): Request {
|
|||||||
class RequestJSONEventsHandler extends JSONHandler {
|
class RequestJSONEventsHandler extends JSONHandler {
|
||||||
|
|
||||||
public action: string;
|
public action: string;
|
||||||
public msg: string;
|
public message: string;
|
||||||
public username: string;
|
public username: string;
|
||||||
public filter_handle: string | null;
|
public filter_handle: string | null;
|
||||||
|
|
||||||
@ -79,8 +79,8 @@ class RequestJSONEventsHandler extends JSONHandler {
|
|||||||
|
|
||||||
if (name == "action") {
|
if (name == "action") {
|
||||||
this.action = value;
|
this.action = value;
|
||||||
} else if (name == "msg") {
|
} else if (name == "message") {
|
||||||
this.msg = value;
|
this.message = value;
|
||||||
} else if (name == "username") {
|
} else if (name == "username") {
|
||||||
this.username = value;
|
this.username = value;
|
||||||
this.filter_handle = value;
|
this.filter_handle = value;
|
||||||
|
@ -8,11 +8,11 @@ export abstract class Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Message {
|
export class Message {
|
||||||
msg: string;
|
message: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
constructor(msg: string, username: string) {
|
constructor(message: string, username: string) {
|
||||||
this.msg = msg;
|
this.message = message;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ export class UnknownResponse extends Response {
|
|||||||
let encoder = new JSONEncoder();
|
let encoder = new JSONEncoder();
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("action", "Unknown");
|
encoder.setString("action", "Unknown");
|
||||||
encoder.setString("msg", "cannot username request");
|
encoder.setString("message", "cannot username request");
|
||||||
encoder.popObject();
|
encoder.popObject();
|
||||||
|
|
||||||
return encoder.toString();
|
return encoder.toString();
|
||||||
@ -34,17 +34,16 @@ export class UnknownResponse extends Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PostResponse extends Response {
|
export class PostResponse extends Response {
|
||||||
msgCount: u32;
|
count: u32;
|
||||||
constructor(msgCount: u32) {
|
constructor(count: u32) {
|
||||||
super();
|
super();
|
||||||
this.msgCount = msgCount;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(): string {
|
serialize(): string {
|
||||||
let encoder = new JSONEncoder();
|
let encoder = new JSONEncoder();
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("action", "Post");
|
encoder.setInteger("count", this.count);
|
||||||
encoder.setInteger("count", this.msgCount);
|
|
||||||
encoder.popObject();
|
encoder.popObject();
|
||||||
|
|
||||||
return encoder.toString();
|
return encoder.toString();
|
||||||
@ -62,12 +61,11 @@ export class FetchResponse extends Response {
|
|||||||
serialize(): string {
|
serialize(): string {
|
||||||
let encoder = new JSONEncoder();
|
let encoder = new JSONEncoder();
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("action", "Fetch");
|
|
||||||
encoder.pushArray("posts");
|
encoder.pushArray("posts");
|
||||||
for (let i = 0; i < this.posts.length; i++) {
|
for (let i = 0; i < this.posts.length; i++) {
|
||||||
let twit = this.posts[i];
|
let twit = this.posts[i];
|
||||||
encoder.pushObject(null);
|
encoder.pushObject(null);
|
||||||
encoder.setString("msg", twit.msg);
|
encoder.setString("message", twit.message);
|
||||||
encoder.setString("username", twit.username);
|
encoder.setString("username", twit.username);
|
||||||
encoder.popObject();
|
encoder.popObject();
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ fn run(arg: String) -> String {
|
|||||||
api::serialize(&result)
|
api::serialize(&result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_post(msg: String, username: String) -> AppResult<Response> {
|
fn add_post(message: String, username: String) -> AppResult<Response> {
|
||||||
// Store post
|
// Store post
|
||||||
model::add_post(msg, username)?;
|
model::add_post(message, username)?;
|
||||||
// Get total number of posts
|
// Get total number of posts
|
||||||
let count = model::get_posts_count()?;
|
let count = model::get_posts_count()?;
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ pub fn create_scheme() -> AppResult<()> {
|
|||||||
Ok(log::info!("creating scheme"))
|
Ok(log::info!("creating scheme"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_post(msg: String, username: String) -> AppResult<()> {
|
pub fn add_post(message: String, username: String) -> AppResult<()> {
|
||||||
Ok(log::info!("add post {} {}", msg, username))
|
Ok(log::info!("add post {} {}", message, username))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_posts() -> AppResult<String> {
|
pub fn get_all_posts() -> AppResult<String> {
|
||||||
|
@ -11,7 +11,7 @@ fn init() {
|
|||||||
#[invocation_handler(init_fn = init)]
|
#[invocation_handler(init_fn = init)]
|
||||||
fn run(nickname: String) -> String {
|
fn run(nickname: String) -> String {
|
||||||
// Create table for messages storage
|
// Create table for messages storage
|
||||||
database::query("CREATE TABLE messages(msg text, username text)".to_string())
|
database::query("CREATE TABLE messages(message text, username text)".to_string())
|
||||||
.expect("error on CREATE TABLE");
|
.expect("error on CREATE TABLE");
|
||||||
|
|
||||||
// Insert message 'Hello, username!' using `nickname` as author's username
|
// Insert message 'Hello, username!' using `nickname` as author's username
|
||||||
@ -29,7 +29,7 @@ fn run(nickname: String) -> String {
|
|||||||
// Get all messages as JSON via SQLite's JSON extension
|
// Get all messages as JSON via SQLite's JSON extension
|
||||||
database::query(
|
database::query(
|
||||||
"SELECT json_group_array(
|
"SELECT json_group_array(
|
||||||
json_object('msg', msg, 'username', username)
|
json_object('message', message, 'username', username)
|
||||||
) AS json_result FROM (SELECT * FROM messages)"
|
) AS json_result FROM (SELECT * FROM messages)"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
|
@ -37,9 +37,9 @@ fn run(arg: String) -> String {
|
|||||||
api::serialize(&result)
|
api::serialize(&result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_post(msg: String, username: String) -> AppResult<Response> {
|
fn add_post(message: String, username: String) -> AppResult<Response> {
|
||||||
// Store post
|
// Store post
|
||||||
model::add_post(msg, username)?;
|
model::add_post(message, username)?;
|
||||||
// Get total number of posts
|
// Get total number of posts
|
||||||
let count = model::get_posts_count()?;
|
let count = model::get_posts_count()?;
|
||||||
|
|
||||||
|
@ -5,20 +5,20 @@ use crate::errors::err_msg;
|
|||||||
use crate::errors::AppResult;
|
use crate::errors::AppResult;
|
||||||
|
|
||||||
pub fn create_scheme() -> AppResult<()> {
|
pub fn create_scheme() -> AppResult<()> {
|
||||||
database::query("CREATE TABLE messages(msg text, username text)".to_string())
|
database::query("CREATE TABLE messages(message text, username text)".to_string())
|
||||||
.map_err(|e| err_msg(&format!("Error creating table messages: {}", e)))
|
.map_err(|e| err_msg(&format!("Error creating table messages: {}", e)))
|
||||||
.map(drop)
|
.map(drop)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_post(msg: String, username: String) -> AppResult<()> {
|
pub fn add_post(message: String, username: String) -> AppResult<()> {
|
||||||
database::query(format!(
|
database::query(format!(
|
||||||
r#"INSERT INTO messages VALUES("{}","{}")"#,
|
r#"INSERT INTO messages VALUES("{}","{}")"#,
|
||||||
msg, username
|
message, username
|
||||||
))
|
))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
err_msg(&format!(
|
err_msg(&format!(
|
||||||
"Error inserting post {} by {}: {}",
|
"Error inserting post {} by {}: {}",
|
||||||
msg, username, e
|
message, username, e
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.map(drop)
|
.map(drop)
|
||||||
@ -27,7 +27,7 @@ pub fn add_post(msg: String, username: String) -> AppResult<()> {
|
|||||||
pub fn get_all_posts() -> AppResult<String> {
|
pub fn get_all_posts() -> AppResult<String> {
|
||||||
database::query(
|
database::query(
|
||||||
"SELECT json_group_array(
|
"SELECT json_group_array(
|
||||||
json_object('msg', msg, 'username', username)
|
json_object('message', message, 'username', username)
|
||||||
) AS json_result FROM (SELECT * FROM messages)"
|
) AS json_result FROM (SELECT * FROM messages)"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
@ -37,7 +37,7 @@ pub fn get_all_posts() -> AppResult<String> {
|
|||||||
pub fn get_posts_by_username(username: String) -> AppResult<String> {
|
pub fn get_posts_by_username(username: String) -> AppResult<String> {
|
||||||
database::query(format!(
|
database::query(format!(
|
||||||
"SELECT json_group_array(
|
"SELECT json_group_array(
|
||||||
json_object('msg', msg, 'username', username)
|
json_object('message', message, 'username', username)
|
||||||
) AS json_result FROM (SELECT * FROM messages where username = '{}')",
|
) AS json_result FROM (SELECT * FROM messages where username = '{}')",
|
||||||
username
|
username
|
||||||
))
|
))
|
||||||
|
Reference in New Issue
Block a user