1# Simple demo, can be used to verify proper Mk4py installation
2
3import Mk4py, sys
4mk = Mk4py
5print sys.argv[0], '- Mk4py', mk.version, '-', sys.platform
6
7# On first run, output should consist of 5 lines:
8#   John Lennon 44
9#   Flash Gordon 42
10#   Flash Gordon 42
11#   John Lennon 44
12#   John Lennon 44
13# Each following run will generate 5 more lines of output
14
15  # create a file called "demo.db"
16db = mk.storage("demo.db",1)
17  # define a view in it called "people", containing three fields
18vw = db.getas("people[first:S,last:S,shoesize:I]")
19
20  # let's append two rows to the end of the view
21vw.append(first='John',last='Lennon',shoesize=44)
22vw.append(first='Flash',last='Gordon',shoesize=42)
23
24  # commit the structure and data to file
25db.commit()
26
27  # a simple loop to print out all rows
28for r in vw:
29  print r.first, r.last, r.shoesize
30
31  # another way to loop, in sorted order
32for r in vw.sort(vw.last):
33  print r.first, r.last, r.shoesize
34
35  # this loop iterates over a selection
36for r in vw.select(first='John'):
37  print r.first, r.last, r.shoesize
38