mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-22 09:31:32 +00:00
step2 fixes
This commit is contained in:
@ -32,8 +32,8 @@ JSON
|
||||
# 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)
|
||||
|
||||
# Parse result as JSON and print to console
|
||||
echo -e "$RESPONSE" | jq .
|
||||
# Parse json or print response as is
|
||||
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
|
||||
|
||||
# Remove frun container
|
||||
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
|
||||
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
|
||||
JSON=$(cat <<JSON
|
||||
{"action":"Post","message":"I'm nice, you're nice, it's nice!","username":"random_joe"}
|
||||
JSON
|
||||
)
|
||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$USER" --compressed | jq -r .result.data | base64 -D)
|
||||
|
||||
# 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)
|
||||
|
||||
# Parse result as JSON and print to console
|
||||
echo -e "$RESPONSE" | jq .
|
||||
# Parse json or print response as is
|
||||
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
|
||||
echo
|
||||
|
||||
# Remove frun container
|
||||
echo -e "Stopping..."
|
||||
|
@ -11,17 +11,20 @@ fn init() {
|
||||
#[invocation_handler(init_fn = init)]
|
||||
fn run(nickname: String) -> String {
|
||||
// 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
|
||||
database::query(format!(
|
||||
r#"INSERT INTO messages VALUES("{}","{}")"#,
|
||||
"Hello, username!", nickname
|
||||
));
|
||||
))
|
||||
.expect("error on INSERT INTO");
|
||||
|
||||
// Get all messages
|
||||
let messages = database::query("SELECT * FROM messages".to_string());
|
||||
log::info!("messages: {}", messages);
|
||||
let 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
|
||||
database::query(
|
||||
@ -30,4 +33,5 @@ fn run(nickname: String) -> String {
|
||||
) AS json_result FROM (SELECT * FROM messages)"
|
||||
.to_string(),
|
||||
)
|
||||
.expect("error on SELECT as json")
|
||||
}
|
||||
|
Reference in New Issue
Block a user