Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_syntax/src/apps/db.rs

3.3 KiB, 23 runs

created by r1870400018:1037, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use crate::{
2 Syntax,
3 arg::{
4 Arg,
5 ArgConfig,
6 },
7 cmd::{
8 Cmd,
9 CmdConfig,
10 },
11};
12
13use oxedyne_fe2o3_core::prelude::*;
14use oxedyne_fe2o3_jdat::prelude::*;
15
16/// Works with the `oxedyne_fe2o3_iop_db::Database` trait.
17pub fn generic_database(
18 mut s: Syntax,
19 mcid_kind: Kind,
20 uid_kind: Kind,
21)
22 -> Outcome<Syntax>
23{
24 // ┌───────────────────────┐
25 // │ DATABASE │
26 // └───────────────────────┘
27
28 let arg_msg_cmd_id = Arg::from(ArgConfig {
29 name: fmt!("msg_cmd_id"),
30 hyph1: Some(fmt!("mcid")),
31 vals: vec![(mcid_kind, fmt!("Message command identifier value")).into()],
32 reqd: true,
33 help: Some(fmt!("Message command identifier")),
34 ..Default::default()
35 });
36 let arg_usr_id = Arg::from(ArgConfig {
37 name: fmt!("usr_id"),
38 hyph1: Some(fmt!("uid")),
39 vals: vec![(uid_kind, fmt!("User identifier value")).into()],
40 reqd: true,
41 help: Some(fmt!("User identifier")),
42 ..Default::default()
43 });
44
45 // ---------------------------------------------------------------------------------------------
46 // Command: insert
47 // ---------------------------------------------------------------------------------------------
48 let mut cmd = Cmd::from(CmdConfig {
49 name: fmt!("insert"),
50 help: Some(fmt!("Insert (key, value) daticles into database")),
51 vals: vec![
52 (Kind::Unknown, fmt!("Key")).into(),
53 (Kind::Unknown, fmt!("Value")).into(),
54 ],
55 cat: fmt!("Database"),
56 ..Default::default()
57 });
58 cmd = res!(cmd.add_arg(arg_msg_cmd_id.clone()));
59 cmd = res!(cmd.add_arg(arg_usr_id.clone()));
60 s = res!(s.add_cmd(cmd));
61 // =============================================================================================
62
63 // ---------------------------------------------------------------------------------------------
64 // Command: get
65 // ---------------------------------------------------------------------------------------------
66 let mut cmd = Cmd::from(CmdConfig {
67 name: fmt!("get"),
68 help: Some(fmt!("Get database value for given key daticle")),
69 vals: vec![(Kind::Unknown, fmt!("Key")).into()],
70 cat: fmt!("Database"),
71 ..Default::default()
72 });
73 cmd = res!(cmd.add_arg(arg_msg_cmd_id.clone()));
74 s = res!(s.add_cmd(cmd));
75 // =============================================================================================
76
77 // ---------------------------------------------------------------------------------------------
78 // Command: delete
79 // ---------------------------------------------------------------------------------------------
80 let mut cmd = Cmd::from(CmdConfig {
81 name: fmt!("delete"),
82 help: Some(fmt!("Delete given key from database")),
83 vals: vec![(Kind::Unknown, fmt!("Key")).into()],
84 cat: fmt!("Database"),
85 ..Default::default()
86 });
87 cmd = res!(cmd.add_arg(arg_msg_cmd_id.clone()));
88 cmd = res!(cmd.add_arg(arg_usr_id.clone()));
89 s = res!(s.add_cmd(cmd));
90 // =============================================================================================
91
92 Ok(s)
93}