Some examples of Midgard2 GIR usage
Created
December 28, 2011 16:57
-
-
Save bergie/1528677 to your computer and use it in GitHub Desktop.
Midgard2 GIR examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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