Skip to content

Instantly share code, notes, and snippets.

@bergie
Created December 28, 2011 16:57
Show Gist options
  • Save bergie/1528677 to your computer and use it in GitHub Desktop.
Save bergie/1528677 to your computer and use it in GitHub Desktop.
Midgard2 GIR examples

Some examples of Midgard2 GIR usage

// Get Midgard via GIR
const Midgard = imports.gi.Midgard;
Midgard.init();
print(Midgard.version());
var config = new Midgard.Config();
config.dbtype = 'SQLite';
config.dbdir = '/tmp';
config.database = 'phpcr';
config.loglevel = 'debug';
print(config.get_database_type());
var connection = new Midgard.Connection();
connection.open_config(config);
var storage = new Midgard.QueryStorage({
dbclass: 'midgard_node'
});
var qs = new Midgard.QuerySelect({
connection: connection,
storage: storage
});
qs.execute();
var nodes = qs.list_objects();
for (var i in nodes) {
print(nodes[i].name);
}
# Get GObject Introspection
gir = require 'gir'
do gir.init
# Get Midgard via GIR
midgard = gir.load 'Midgard'
do midgard.init
console.log midgard.version()
config = new midgard.Config
config.__call__ 'set_database_type', 'SQLite'
config.__call__ 'set_property', 'dbdir', '/tmp'
config.__call__ 'set_property', 'database', 'phpcr'
config.__call__ 'set_property', 'loglevel', 'debug'
console.log config.__call__ 'get_database_type'
connection = new midgard.Connection
connection.__call__ 'open_config', config
storage = new midgard.QueryStorage
dbclass: 'midgard_node'
qs = new midgard.QuerySelect
connection: connection
storage: storage
qs.__call__ 'execute'
for node in qs.__call__ 'list_objects'
console.log node.__call__ 'get_property', 'name'
<?php
echo mgd_version() . "\n";
$config = new midgard_config();
$config->dbdir = '/tmp';
$config->dbtype = 'SQLite';
$config->database = 'phpcr';
$config->loglevel = 'debug';
echo $config->dbtype . "\n";
$connection = midgard_connection::get_instance();
$connection->open_config($config);
$storage = new midgard_query_storage('midgard_node');
$qs = new midgard_query_select($storage);
$qs->execute();
foreach ($qs->list_objects() as $node) {
echo $node->name . "\n";
}
from gi.repository import Midgard
# Initialize types in GType system */
Midgard.init()
print Midgard.version()
# Read configuration file
config = Midgard.Config()
config.set_property('dbdir', '/tmp')
config.set_property('dbtype', 'SQLite')
config.set_property('database', 'phpcr')
config.set_property('loglevel', 'debug')
print config.get_database_type()
# Establish connection
mgd = Midgard.Connection()
mgd.open_config(config)
storage = Midgard.QueryStorage(dbclass = 'midgard_node')
qs = Midgard.QuerySelect(connection = mgd, storage = storage)
qs.execute()
for node in qs.list_objects():
print node.get_property('name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment