1+ // FurrDB CRUD Demo (Deno TypeScript)
2+ // Demonstrates basic CRUD operations for a user profile
3+
4+ const HOST = "127.0.0.1" ;
5+ const PORT = 7070 ;
6+
7+ // Helper to send a command and receive a response
8+ async function sendCommand ( conn : Deno . Conn , cmd : string ) : Promise < string > {
9+ const encoder = new TextEncoder ( ) ;
10+ const decoder = new TextDecoder ( ) ;
11+ await conn . write ( encoder . encode ( cmd + "\n" ) ) ;
12+ let resp = "" ;
13+ while ( ! resp . endsWith ( "\n" ) ) {
14+ const buf = new Uint8Array ( 1024 ) ;
15+ const n = await conn . read ( buf ) ;
16+ if ( n === null ) break ;
17+ resp += decoder . decode ( buf . subarray ( 0 , n ) ) ;
18+ }
19+ return resp . trim ( ) ;
20+ }
21+
22+ // Main demo logic
23+ const conn = await Deno . connect ( { hostname : HOST , port : PORT } ) ;
24+ console . log ( "Connected to FurrDB\n" ) ;
25+
26+ // Create (SET user:1 name and email)
27+ console . log ( "[CREATE] Set user:1 name and email" ) ;
28+ console . log ( await sendCommand ( conn , 'SET user:1:name Alice' ) ) ;
29+ console . log ( await sendCommand ( conn , 'SET user:1:email alice@example.com' ) ) ;
30+
31+ // Read (GET user:1 name and email)
32+ console . log ( "\n[READ] Get user:1 name and email" ) ;
33+ console . log ( 'Name:' , await sendCommand ( conn , 'GET user:1:name' ) ) ;
34+ console . log ( 'Email:' , await sendCommand ( conn , 'GET user:1:email' ) ) ;
35+
36+ // Update (SET user:1 name)
37+ console . log ( "\n[UPDATE] Update user:1 name" ) ;
38+ console . log ( await sendCommand ( conn , 'SET user:1:name Alicia' ) ) ;
39+ console . log ( 'Updated Name:' , await sendCommand ( conn , 'GET user:1:name' ) ) ;
40+
41+ // Exists
42+ console . log ( "\n[EXISTS] Check if user:1:email exists" ) ;
43+ console . log ( 'Exists:' , await sendCommand ( conn , 'EXISTS user:1:email' ) ) ;
44+
45+ // Delete (DEL user:1 email)
46+ console . log ( "\n[DELETE] Delete user:1:email" ) ;
47+ console . log ( await sendCommand ( conn , 'DEL user:1:email' ) ) ;
48+ console . log ( 'Email after delete:' , await sendCommand ( conn , 'GET user:1:email' ) ) ;
49+
50+ // List all keys
51+ console . log ( "\n[KEYS] List all keys" ) ;
52+ console . log ( await sendCommand ( conn , 'KEYS' ) ) ;
53+
54+ // Exit
55+ await sendCommand ( conn , 'EXIT' ) ;
56+ conn . close ( ) ;
57+ console . log ( "\nConnection closed" ) ;
58+
59+ export { } ;
0 commit comments