mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-22 17:41:32 +00:00
step2 fixes
This commit is contained in:
@ -32,8 +32,8 @@ JSON
|
|||||||
# Send json as a request, and receive result
|
# Send json as a request, and receive result
|
||||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D)
|
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D)
|
||||||
|
|
||||||
# Parse result as JSON and print to console
|
# Parse json or print response as is
|
||||||
echo -e "$RESPONSE" | jq .
|
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
|
||||||
|
|
||||||
# Remove frun container
|
# Remove frun container
|
||||||
echo -e "Stopping..."
|
echo -e "Stopping..."
|
||||||
|
@ -28,18 +28,14 @@ sleep 1 && (docker logs -f frun 2>&1 &) | grep -q initialized && sleep 1
|
|||||||
|
|
||||||
# Send our username to the application
|
# Send our username to the application
|
||||||
echo -e "Sending request..."
|
echo -e "Sending request..."
|
||||||
|
echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'$USER --compressed"
|
||||||
|
echo
|
||||||
|
|
||||||
# Assign json to a variable using heredoc technique
|
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$USER" --compressed | jq -r .result.data | base64 -D)
|
||||||
JSON=$(cat <<JSON
|
|
||||||
{"action":"Post","message":"I'm nice, you're nice, it's nice!","username":"random_joe"}
|
|
||||||
JSON
|
|
||||||
)
|
|
||||||
|
|
||||||
# Send json as a request, and receive result
|
# Parse json or print response as is
|
||||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D)
|
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
|
||||||
|
echo
|
||||||
# Parse result as JSON and print to console
|
|
||||||
echo -e "$RESPONSE" | jq .
|
|
||||||
|
|
||||||
# Remove frun container
|
# Remove frun container
|
||||||
echo -e "Stopping..."
|
echo -e "Stopping..."
|
||||||
|
@ -11,17 +11,20 @@ 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(msg text, username text)".to_string())
|
||||||
|
.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
|
||||||
database::query(format!(
|
database::query(format!(
|
||||||
r#"INSERT INTO messages VALUES("{}","{}")"#,
|
r#"INSERT INTO messages VALUES("{}","{}")"#,
|
||||||
"Hello, username!", nickname
|
"Hello, username!", nickname
|
||||||
));
|
))
|
||||||
|
.expect("error on INSERT INTO");
|
||||||
|
|
||||||
// Get all messages
|
// Get all messages
|
||||||
let messages = database::query("SELECT * FROM messages".to_string());
|
let messages =
|
||||||
log::info!("messages: {}", messages);
|
database::query("SELECT * FROM messages".to_string()).expect("error on SELECT *");
|
||||||
|
log::info!("messages: {:?}", messages);
|
||||||
|
|
||||||
// Get all messages as JSON via SQLite's JSON extension
|
// Get all messages as JSON via SQLite's JSON extension
|
||||||
database::query(
|
database::query(
|
||||||
@ -30,4 +33,5 @@ fn run(nickname: String) -> String {
|
|||||||
) AS json_result FROM (SELECT * FROM messages)"
|
) AS json_result FROM (SELECT * FROM messages)"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
|
.expect("error on SELECT as json")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user