Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
79
Task/Simple-database/11l/simple-database.11l
Normal file
79
Task/Simple-database/11l/simple-database.11l
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
T Item
|
||||
String name, date, category
|
||||
|
||||
F (name, date, category)
|
||||
.name = name
|
||||
.date = date
|
||||
.category = category
|
||||
|
||||
F String()
|
||||
R .name‘, ’(.date)‘, ’(.category)
|
||||
|
||||
V db_filename = ‘simdb.csv’
|
||||
|
||||
F load()
|
||||
[Item] db
|
||||
L(line) File(:db_filename).read().rtrim("\n").split("\n")
|
||||
V item = line.split(‘, ’)
|
||||
db.append(Item(item[0], item[1], item[2]))
|
||||
R db
|
||||
|
||||
F store(item)
|
||||
File(:db_filename, ‘a’).write(String(item)"\n")
|
||||
|
||||
F printUsage()
|
||||
print(|‘
|
||||
Usage:
|
||||
simdb cmd [categoryName]
|
||||
add add item, followed by optional category
|
||||
latest print last added item(s), followed by optional category
|
||||
all print all
|
||||
For instance: add "some item name" "some category name’)
|
||||
|
||||
F addItem(args)
|
||||
I args.len < 2
|
||||
printUsage()
|
||||
R
|
||||
|
||||
V date = Time().strftime(‘%Y-%m-%d %H:%M:%S’)
|
||||
V cat = I args.len == 3 {args[2]} E ‘none’
|
||||
store(Item(args[1], date, cat))
|
||||
|
||||
F printLatest(a)
|
||||
V db = load()
|
||||
I db.empty
|
||||
print(‘No entries in database.’)
|
||||
R
|
||||
|
||||
I a.len == 2
|
||||
L(item) reversed(db)
|
||||
I item.category == a[1]
|
||||
print(item)
|
||||
L.break
|
||||
L.was_no_break
|
||||
print(‘There are no items for category '’a[1]‘'’)
|
||||
E
|
||||
print(db.last)
|
||||
|
||||
F printAll()
|
||||
V db = load()
|
||||
I db.empty
|
||||
print(‘No entries in database.’)
|
||||
R
|
||||
|
||||
L(item) db
|
||||
print(item)
|
||||
|
||||
:start:
|
||||
I :argv.len C 2..4
|
||||
S :argv[1].lowercase()
|
||||
‘add’
|
||||
addItem(:argv[1..])
|
||||
‘latest’
|
||||
printLatest(:argv[1..])
|
||||
‘all’
|
||||
printAll()
|
||||
E
|
||||
printUsage()
|
||||
E
|
||||
printUsage()
|
||||
Loading…
Add table
Add a link
Reference in a new issue