ELENESSKI GAMES
  • Home
  • Games
    • Worzzler
    • The Lost Tribes
  • Unity
    • Facade Generator for Archimatix
    • Elenesski Object Database
    • Generic Move Camera
    • Unity C# Library
  • SQLINQ
    • Change Log
    • Concepts >
      • Overview
      • The Patterns
      • Database & Factories
      • Working with Tables
      • Custom Queries
      • Lazy Loading
      • Units of Work
    • Video Tutorials
    • Getting Started
    • Code Examples >
      • Implementing Behavior
      • Finding Objects
      • Custom Searches
      • Converters and Transformers
      • Object Association Management
      • New Objects
      • Creating Database
      • Associating Objects
      • Deleting Objects
      • Validating Objects
      • Saving
    • Sample Model >
      • Tutorial Model
      • Table Classes Code
      • Domain Classes Code
      • Factories Code
    • OSX Developers
    • Bridge Building
    • External Websites
    • Class Documentation
  • Presentations
    • 3D Ship Design
  • Music
    • Jamendo (Main)
    • Blend
    • Sound Cloud
    • Mixcloud (DJ)
    • DJ Demos
  • YouTube

creating a database and writing to it

The following code was written for Windows, the code below it is for OSX.  As you can see the code is identical except for the filename. 

You will also notice that Factory.Initialize() is not called.  This is because it's not required unless you are reading from the database.

You should also notice that there is no database open/close operation.  This is because the Save operation opens, writes and closes the database as a single set.  Once the Save takes place and returns the data is automatically persisted.

If you want to write several instances in memory to the database as a set, use the Repository.Commit() method; it implements a Unit of Work.  It's faster to write 8-10  instances with myObject.Save(), but if you have hundreds to thousands of inserts, a Repository.Commit() will be significantly faster.
Windows:

    void Awake () {
        // Identify File Location
        Repository.InitializeRepository(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\test.db");

        // Build SQL Tables and Indexes
        Factory.MakeDatabase ();

        // Construct an Object
        NebulaObject NEBULA = new NebulaObject (0, false, "Bob", 123, 0f, 0f, 0f, System.Guid.Empty, 400f, 0.65f);

       // Save Object to Database
        NEBULA.Save ();
    }

Mac OSX:


    void Awake () {
        // Identify File Location
        Repository.InitializeRepository("/Volumes/Data/SQLINQData/test.db");

        // Build SQL Tables and Indexes
        Factory.MakeDatabase ();

        // Construct an Object
        NebulaObject NEBULA = new NebulaObject (0, false, "Bob", 123, 0f, 0f, 0f, System.Guid.Empty, 400f, 0.65f);

       // Save Object to Database
        NEBULA.Save ();
    }