-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.vala
More file actions
47 lines (35 loc) · 1.2 KB
/
example.vala
File metadata and controls
47 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* valac --debug --pkg midgard2 -o midgard-vala-example example.vala --vapidir=./ */
using GLib;
using Midgard;
namespace MidgardValaExample {
void main() {
Midgard.init();
Midgard.Config config = new Midgard.Config();
try {
config.read_file ("midgard_test", true);
} catch ( GLib.Error e) {
}
Midgard.Connection cnc = new Midgard.Connection();
if (!cnc.open_config (config))
GLib.error ("Not connected to database \n");
/* cnc.set_loglevel ("debug", null); */
Midgard.Object page = new Midgard.Object (cnc, "midgard_page", null);
page.set ("name", "Hello Vala");
if (page.create()) {
string pname;
page.get ("name", out pname);
Midgard.Timestamp created = page.metadata.created;
GLib.print ("Created new page '%s' identified by guid %s at %s \n", pname, page.guid, created.get_string());
}
else {
GLib.print ("Couldn't create new page because: %s \n", cnc.get_error_string());
}
Midgard.QueryBuilder builder = new Midgard.QueryBuilder (cnc, "midgard_page");
unowned GLib.Object[] objects = builder.execute ();
foreach (GLib.Object object in objects){
string guid;
object.get ("guid", out guid);
GLib.print ("Object %s \n", guid);
}
}
}