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.
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 ();
}
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 ();
}