Elenesski Object Database  EODB and NEODB
The Memento Pattern Database for Unity
29 Local - Video Tutorials

EODB Tutorials Playlist

EODB Quick Start

The purpose of this video is to give a quick start of how to create, store and retreive a single object out of EODB.

This is the code that was created from this video, however, I've modified it a little bit to provide additional documentation:

using Assets.ElenesskiDB.Kernel;
using UnityEngine;
using System.Collections;

public class SimpleLoadSave : MonoBehaviour , IEODBClass {

    void Awake() {
        // We create a database here in this script to keep it simple, however, normally,
        // you would create/open a database elsewhere, then reference where the database is.
        Database = new EODB(@"Z:\TutorialDB\Simple");
    }

    // Use this for initialization
    void Start () {
        // This LOADS -5 from the Database referenced from this (which is implementing IEODBClass)
        // the TRUE is an auto create; basically it says if OID -5 doesn't exist, automatically
        // call "DBSave()" on "this".
        new EODBDescriptor(-5, this, true);     

    }

    // Update is called once per frame
    void Update () {
        // Note: This is done here to simplify this code.  Normally you will have explicit
        //       logic that save individual objects.
        DBSave();

        // Note: You normally call this with a "Save Game" operation in a different part
        //       of your game.
        Database.CommitToFileSystem();
    }

    public EODB Database { get; private set; }      // Where is our data?
    public int OID { get; set; }                    // Unique object identifier
    public byte Version { get; set; }               // Version of the data

    // A name that describes this object.  If you were storing multiple objects of this class in
    // the database, you'd use this name to retreive them.  For example, say:
    //     IEnumerable<int> SIMPLE_OIDS = Database.AllByClass("Simple");
    public string ClassName() {
        return "Simple";
    }

    // This Definition method is used to ensure that the same layout used to save an object is the same
    // layout and sequence used to load an object.  EODB does not store any header information with
    // individual fields, so it's critical to make sure it's the same definition.
    public void Definition(EODBDescriptor aDescriptor) {

        // Recognizes that .position is a Vector3 and automatically loads/saves the x,y,z floats
        aDescriptor.Structure(()=>gameObject.transform.position,A=>gameObject.transform.position=A);

        // Recognizes that .position is a Quaternion and automatically loads/saves the x,y,z,w floats
        aDescriptor.Structure(()=>gameObject.transform.rotation,A=>gameObject.transform.rotation=A);
    }

    // A method that is callable externally from this object to save the object.
    public void DBSave() {
        new EODBDescriptor(this, -5);
    }
}

EODB Introduction to Indexes

The purpose of this video is to give a quick overview of indexes. We create a bool index called "left" that has values set to TRUE if the Vector3's x position is < 0. The video shows that indexes do not have to be of the values you create, in fact they can be of any derived type:

EODB Create Index Values Conditionally

The purpose of this video is to show a variation of the previous video. To show that you can add logic to the creation of your index. In this video, as objects are being saved, there is a condition that says, only store a value on the index if the Vector3's y position > 0. The video goes on to describe the various combinations.

NOTE

The video doesn't describe what to do if were to update CITestObject. That means that if we decide to update Position to some new value, we should update the index appropriately. Right now, if the new position.y is > 0, it will get added to the index. But what if the new position.y <= 0. This code would not remove it from the index, but there is a way to do it; by sending NULL to the .Index() method:

Therefore, the conditional should change from:

    if ( Position.y > 0 )
        aDescriptor.Index("cileft",()=>Position.x < 0);

to:

    if ( Position.y > 0 )
        aDescriptor.Index("cileft",()=>Position.x < 0);
    else
        aDescriptor.Index("cileft",null);

In the revised condition, we send a NULL value to the "cileft" index. This will cause the OID to be removed from the index only if it was already there.

EODB Lists

The purpose of this tutorial is to explain how to store a List<T> as a composite and to show the major differences between the Elenesski Object Database and ORM.

The video also shows how Dynamic Data works. Dynamic Data is when you have multiple objects of the same class type but don't know what what the object identifiers are. We use this call to extract all the object instances called "Player" from the database.

Database.AllByClass("Player")

We know we are dealing with "Player" objects because in our Player : IEODBClass object we use that name:

PlayerTable.png
IEODBClass Identifying Player classes

A composite, as shown in this UML diagram is an object that contains several other objects. With relational databases, there is no way to easily represent several objects in a Player Table, so we need to create a separate Inventory Table to represent all the objects. Largely the representation of the Player -> Inventory in the model is a composite, but in the database we have to represent it as a aggregate.

EODBvsORM.png
Difference Between EODB and ORM

In EODB, you can store your composite as a composite, and this video shows you how to do just that using

List<Inventory> Inventories;

Note: in this video, I don't explicitly identify this ability, but you can do inventory as an array instead of a list.

Inventory[] Inventories;

See the documentation on Class Definitions ::: List in the Usage Guide for more information.

EODB Arrays

This tutorial requires you watch the video on Lists, and it describes how to save and load arrays; T[]

EODB Arrays

This tutorial requires you watch the video on Lists, and it describes how to save and load ICollection with a KeyValuePair.