Siaqodb stores its data in a file called "data.mdb" within a specified folder on disk. As a best practice we recommend opening a database only once and then using that database instance throughout your application runtime. The examples below show factory classes that create and open Siaqodb database instances for each platform supported.

Setting your License

Licensed versions of Siaqodb require a license code in order to function. Add the following code before you perform other database actions to activate your license:

Sqo.SiaqodbConfigurator.SetLicense("[Paste your provided license key here...]");

Custom Folder Name

You may customize the folder name for your database storage file by passing the folder name into the main Siaqodb constructor. The SiaqodbFactory example shows how to customize this path.

SiaqodbFactory: Full Example

Note: The SiaqodbFactory class is now included in Siaqodb directly as of version 5.5.0.10.

class SiaqodbFactory
{
    public static string siaoqodbPath;
    private static Siaqodb instance;
    ///<summary>
    /// Set the path where the database file will reside
    ///</summary>
    public static void SetPath(string path)
    {
        siaoqodbPath = path;
    }
    ///<summary>
    /// Acquire an instance of the database engine
    ///</summary>
    public static Siaqodb GetInstance()
    {
        if (instance == null)
        {
            instance = new Siaqodb(siaoqodbPath);
        }
        return instance;
    }
    ///<summary>
    /// Close the database
    ///</summary>
    public static void CloseDatabase()
    {
        if (instance != null)
        {
            instance.Close();
            instance = null;
        }
    }
}

For your reference, here is a SiaqodbFactory class that was created by a customer; this class supports multiple named instances of Siaqodb and is useful if you need more than one database in your application.

using System;
using Sqo;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
[assembly: Dependency(typeof(SiaqodbFactory))]
namespace SiaqoTasky.iOS
{
    public class SiaqodbFactory : ISiaqo
    {
        /// 
        /// The siaqod database variables stord in a dictionary to save time and hopefully memory
        /// 
        private static readonly Dictionary SiaqoDatabases = new Dictionary();
        #region Database management code
        /// 
        /// Gets the database instance or creates one
        /// 
        /// The instance.
        /// Database.
        public ISiaqodb GetInstance(string database)
        {
            try
            {
                //Does it exist in the dictionary...
                Siaqodb db;
                if (SiaqoDatabases != null)
                {
                    if (SiaqoDatabases.TryGetValue(database, out db)) return db;
                }
                //Did not find it so add it...
                var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), database);
                var config = new Configurator();
				// Siaqodb Starter version allows you to store 100 objects per type
				// To obtain a trial or full license please visit https://www.siaqodb.com
				// If you are using a trial or fully licensed version of Siaqodb, uncomment this line and enter your key
				//Sqo.SiaqodbConfigurator.SetLicense("[Paste your provided license key here...]");
				SiaqodbConfigurator.ApplyConfigurator(config);
                db = new Siaqodb(dbpath);
                //Add the instance to the list
                SiaqoDatabases?.Add(database, db);
                return db;
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine(ex.Message);
                }
                return null;
            }
        }
        public bool CloseInstance(string database = "DEFAULTDB")
        {
            try
            {
                Siaqodb db;
                if (SiaqoDatabases != null)
                {
                    if (SiaqoDatabases.TryGetValue(database, out db))
                    {
                        db.Close();
                        return SiaqoDatabases.Remove(database);
                    }
                    //Nothing to do 
                    return true;
                }
                //Nothing to do
                return true;
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine(ex.Message);
                }
                return false;
            }
        }
        public void Shutdown()
        {
            try
            {
                if (SiaqoDatabases != null)
                {
                    foreach (var database in SiaqoDatabases)
                    {
                        database.Value.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
        #endregion
    
    }
}

.NET

SiaqodbFactory.SetPath("D:\databases\sdb");
var sqo = SiaqodbFactory.GetInstance();

SiaqodbFactory: WindowsStore OR WindowsPhone

SiaqodbFactory.SetPath(Windows.Storage.ApplicationData.Current.LocalFolder.Path);
var sqo = SiaqodbFactory.GetInstance();

SiaqodbFactory: Xamarin.iOS

SiaqodbFactory.SetPath(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
var sqo = SiaqodbFactory.GetInstance();

SiaqodbFactory: Xamarin.Android

SiaqodbFactory.SetPath(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
var sqo = SiaqodbFactory.GetInstance();

Using the SiaqodbFactory Instance

Now that we have a static instance, let's create, update and delete an object in the Siaqodb database:

SiaqodbFactory.SetPath("D:\databases\sdb");
var siaqodb = SiaqodbFactory.GetInstance();
Employee employee = new Employee();
employee.FirstName = "John";
employee.LastName = "Walter";
employee.Age = 31;
employee.HireDate = new DateTime(2008, 10, 12);
//insert will occur
siaqodb.StoreObject(employee);
employee.Age = 32;
//update will occur
siaqodb.StoreObject(employee);
//delete will occur
siaqodb.Delete(employee);

Custom Database Size and Type Limits

You may specify the maximum size and types to be stored in your database when it is constructed. The following example will construct a database with a maximum size of 100MB and a maximum of 50 different object types allowed (100/2).
Note, if you do not specify anything here, the database will have a maximum size of 50MB and will be able to contain 25 different types.

Siaqodb sqo = new Siaqodb(objPath, 100 * 1024 * 1024, 100)