Midgard2
Content repository for mobile applications
Henri
Bergius



          Microblogs: @bergie
              http://bergie.iki.fi
Content Repository


Don't invent your own file formats
Content Repository


Objects instead of SQL
Content Repository


            Objects instead of SQL




http://xkcd.com/327/
Content Repository


Signals about changes
Content Repository


Data model is scriptable
Content Repository


Synchronization and sharing
With a content repository
incredible power is at your disposal
Free Content Repositories


•   Schema-based, relational   •   Schema-free
•   Query Builder              •   Javascript map/reduce
•   C, glib, libgda            •   Erlang
•   LGPL                       •   Apache License
•   D-Bus signals              •   JSON polling via HTTP
•   Library                    •   Daemon
          midgard2.org              couchdb.apache.org
...and they talk to each other
The Midgard Project
•   Free software project    •   Object-Relational
    since 1999                   Mapping, trees, D-Bus
                                 signals
•   Contributors from most
    European countries       •   APIs for C, PHP, Python,
                                 Vala, Objective-C, ...
•   Synchronized release
    model, every 6 months    •   Linux, Mac, Maemo
Midgard on Maemo 5




Conboy: notes on your phone
Midgard on Maemo 5




Workstreamer: project tracking for N900
Midgard on the web




Qaiku.com: conversational microblogging
Getting started with Midgard
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
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>
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');
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();
}
import antigravity




http://xkcd.com/353/
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')
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();
}
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);
       }
any tools you use, Midgard is there
...maybe even in your finger
How about Qt?
•   Midgard already
    works in PySide
    applications
•   Would be great to
    have proper Qt
    support
•   Anybody want to
    help with this?
Tree access

•   Parent-child relations
    •   get_parent()
    •   list_children()
•   Access via named paths
    •   get_by_path()
Extending objects
•   Subclasses in MgdSchema
    <type name="bossa_attendee" extends="midgard_person">
       <property name="likesbeer" type="boolean" default="true" />
    </type>
•   Ad-hoc additional properties
    object.set_parameter('bossa', 'key', 'value')
    value = object.get_parameter('bossa', 'key')
•   Binary attachments are also supported
    •   Metadata in repository, file in filesystem
    •   API provides access to filehandles
Midgard MVC

Put your content repository on the web
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
Midgard MVC




Tomboy web synchronization with Midgard
Midgard Runtime
Explore the possibilities
           of content repositories




midgard2.org   #midgard on FreeNode   @MidgardProject

Midgard2 - Content Repository for mobile applications

  • 1.
  • 2.
    Henri Bergius Microblogs: @bergie http://bergie.iki.fi
  • 3.
    Content Repository Don't inventyour own file formats
  • 4.
  • 5.
    Content Repository Objects instead of SQL http://xkcd.com/327/
  • 6.
  • 7.
  • 8.
  • 9.
    With a contentrepository incredible power is at your disposal
  • 10.
    Free Content Repositories • Schema-based, relational • Schema-free • Query Builder • Javascript map/reduce • C, glib, libgda • Erlang • LGPL • Apache License • D-Bus signals • JSON polling via HTTP • Library • Daemon midgard2.org couchdb.apache.org
  • 11.
    ...and they talkto each other
  • 12.
    The Midgard Project • Free software project • Object-Relational since 1999 Mapping, trees, D-Bus signals • Contributors from most European countries • APIs for C, PHP, Python, Vala, Objective-C, ... • Synchronized release model, every 6 months • Linux, Mac, Maemo
  • 13.
    Midgard on Maemo5 Conboy: notes on your phone
  • 14.
    Midgard on Maemo5 Workstreamer: project tracking for N900
  • 15.
    Midgard on theweb Qaiku.com: conversational microblogging
  • 16.
  • 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 definedby 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 forPHP <?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 forPHP // 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(); }
  • 21.
  • 22.
    import antigravity # Loadthe 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: PHPvs. 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 Valatoo! /* 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); }
  • 25.
    any tools youuse, Midgard is there
  • 26.
    ...maybe even inyour finger
  • 27.
    How about Qt? • Midgard already works in PySide applications • Would be great to have proper Qt support • Anybody want to help with this?
  • 28.
    Tree access • Parent-child relations • get_parent() • list_children() • Access via named paths • get_by_path()
  • 29.
    Extending objects • Subclasses in MgdSchema <type name="bossa_attendee" extends="midgard_person"> <property name="likesbeer" type="boolean" default="true" /> </type> • Ad-hoc additional properties object.set_parameter('bossa', 'key', 'value') value = object.get_parameter('bossa', 'key') • Binary attachments are also supported • Metadata in repository, file in filesystem • API provides access to filehandles
  • 30.
    Midgard MVC Put yourcontent repository on the web
  • 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
  • 32.
    Midgard MVC Tomboy websynchronization with Midgard
  • 33.
  • 34.
    Explore the possibilities of content repositories midgard2.org #midgard on FreeNode @MidgardProject