17. Installation
• Linux distribution repositories (Ubuntu, Debian, RHEL,
OpenSuse etc) on OBS:
http://download.opensuse.org/repositories/home:/midgardproject:/mjolnir/
• After that Midgard is just an apt-get install python-
midgard2 or apt-get install
php5-midgard2 away
• Maemo 4 and 5 available
in Extras Devel (soon
Extras)
• On OS X use MacPorts
or the ObjC bundle
18. Objects are defined by MgdSchema
<!-- This will be installed to /usr/share/midgard2/schema/ -->
<type name="midgard_person">
<property name="id" type="unsigned integer" primaryfield="id">
<description>Local non-replication-safe database identifier</description>
</property>
<property name="firstname" type="string" index="yes">
<description>First name of the person</description>
</property>
<property name="lastname" type="string" index="yes">
<description>Last name of the person</description>
</property>
<property name="birthdate" type="datetime">
<description>Birth date of the person</description>
</property>
<property name="email" type="string" index="yes">
<description>Email address of the person</description>
</property>
</type>
19. Midgard API for PHP
<?php
// Load the Midgard2 API extension
dl('midgard2.so');
// Set up the repository config
$config = new midgard_config();
$config->dbtype = 'SQLite';
$config->database = 'midgardexample';
// this will store to SQLite in ~/.midgard2/data/midgardexample.db
// Open a Midgard repository connection
$midgard = midgard_connection::get_instance();
$midgard->open_config($config);
// Prepare storage for your data
midgard_storage::create_base_storage();
midgard_storage::create_class_storage('midgard_person');
20. Midgard API for PHP
// Create a new person object
$person = new midgard_person();
$person->firstname = 'Leif';
$person->lastname = 'Eriksson';
$person->create();
// Query system for all persons with lastname "Eriksson"
$qb = new midgard_query_builder('midgard_person');
$qb->add_constraint('lastname', '=', 'Eriksson');
$persons = $qb->execute();
foreach ($persons as $person)
{
echo "{$person->lastname}, {$person->firstname} has GUID {$person-
>guid}n";
// Add an email address and update
$person->email = 'leif@vinland.no';
$person->update();
}
22. import antigravity
# Load the Midgard2 API extension
import _midgard as midgard
# Set up the repository config
configuration = midgard.config()
configuration.dbtype = 'SQLite'
configuration.database = 'midgardexample'
# this will store to SQLite in ~/.midgard2/data/midgardexample.db
# Open a Midgard repository connection
connection = midgard.connection()
connection.open_config(configuration)
# Prepare storage for your data
midgard.storage.create_base_storage()
midgard.storage.create_class_storage('midgard_person')
23. Midgard API: PHP vs. Python
// Create a new person object # Create a new person object
$person = new midgard_person(); person = midgard.mgdschema.midgard_person()
$person->firstname = 'Leif'; person.firstname = 'Leif'
$person->lastname = 'Eriksson'; person.lastname = 'Eriksson'
$person->create(); person.create()
// Query system for all persons with # Query system for all persons with
// lastname "Eriksson" # lastname "Eriksson"
$qb = new qb = midgard.query_builder('midgard_person')
midgard_query_builder('midgard_person'); qb.add_constraint('lastname', '=', 'Eriksson')
$qb->add_constraint('lastname', '=', persons = qb.execute()
'Eriksson'); for person in persons:
$persons = $qb->execute(); print "%s, %s has GUID %s"
foreach ($persons as $person) % (person.lastname, person.firstname,
{ person.guid)
echo "{$person->lastname},” # Add an email address and update
. ” {$person->firstname}” person.email = 'leif@vinland.no'
. “ has GUID {$person->guid}n"; person.update()
// Add an email address and update
$person->email = 'leif@vinland.no';
$person->update();
}
24. Oh, and Vala too!
/* 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();
config.read_file ("midgard_test", true);
Midgard.Connection cnc = new Midgard.Connection();
cnc.open_config (config)
Midgard.Object person = new Midgard.Object (cnc, "midgard_person", null);
person.set ("firstname", "Leif");
if (person.create()) {
string guid;
person.get ("guid", out guid);
GLib.print ("Created new person identified by GUID %s n", guid);
}
31. Midgard MVC
• Very efficient MVC
framework for PHP
• Python and D-Bus for
background processing
• Gettext + intl i18n
• TAL templating
• Full WebDAV support
• Git for packaging and
deployment