mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-17 15:21:20 +00:00
rename lots of things
This commit is contained in:
22
backend-assemblyscript/step2-database-only/assembly/main.ts
Normal file
22
backend-assemblyscript/step2-database-only/assembly/main.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import {log} from "../node_modules/assemblyscript-sdk/assembly/logger";
|
||||
import {query} from "../node_modules/db-connector/assembly/sqlite"
|
||||
|
||||
// main handler for an application
|
||||
export function handler(username: string): string {
|
||||
// Create table for messages storage
|
||||
query(`CREATE TABLE messages(msg text, username text)`);
|
||||
|
||||
// Insert message 'Hello, username!' using `username` as author's username
|
||||
query(`INSERT INTO messages VALUES("Hello, username!","` + username + `")`);
|
||||
|
||||
// Get all messages
|
||||
let messages = query(`SELECT * FROM messages`);
|
||||
log("messages: " + messages);
|
||||
|
||||
// Get all messages as JSON via SQLite's JSON extension
|
||||
return query(
|
||||
`SELECT json_group_array(
|
||||
json_object('msg', msg, 'username', username)
|
||||
) AS json_result FROM (SELECT * FROM messages)`
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user