Elenesski Object Database
EODB and NEODB
The Memento Pattern Database for Unity
|
You need at least a mySQL 5.5 or later database to run NEODB. Creation of the core database is done with a script provided in the distribution, but looks like this:
CREATE TABLE NEODB_NEW_OID ( OID int NOT null, PRIMARY KEY(OID) ); INSERT INTO NEODB_NEW_OID values ( 0 ); CREATE TABLE NEODB_OBJECT_DATA ( OID int NOT null, LOCK_ID VARCHAR(25) not null, CLASSNAME VARCHAR(50) not null, DATA TEXT not null, UPDATE_DTTM INT NOT NULL, PRIMARY KEY(OID) ); CREATE INDEX NEODB_OBJECT_DATA_IX1 ON NEODB_OBJECT_DATA ( LOCK_ID ); CREATE INDEX NEODB_OBJECT_DATA_IX2 ON NEODB_OBJECT_DATA ( CLASSNAME ); CREATE INDEX NEODB_OBJECT_DATA_IX3 ON NEODB_OBJECT_DATA ( UPDATE_DTTM );
This SQL DDL (Data Definition Language) script creates two tables:
Inside EODB, there is no limit as to how large you can make your objects. With NEODB objects should be limited to about 49K of binary data. EODB object data is transformed into base-64 for transport and storage, and this is why the limit is 49K. 49K -> via Base64 -> 64K.
You should carefully decide if you are going to use MEDIUMTEXT instead of TEXT to store your data. The decision to use up to 16Mb should be carefully considered because data transfer and latency becomes and issue when moving large amounts of data around. Furthermore, lots of large data moves can quickly eat up your ISP's database and server limits.
This is why we recommend small data over larger data; even though larger data is supported.
You specify which permanent indexes your database will contain in "neodb_settings.php". You can create, purge and delete dynamic indexes within program logic when you want to isolate data that is for a specific part of your application. Once created they function nearly identically to permanent indexes. See the Usage Guide and Dynamic Indexes for more information.
When creating new permanent indexes you will need to manually create your indexes using the "setup_indexes.php" script. This will read the indexes and create the proper tables. One table per index. Once the indexes are created, it's not necessary to keep "setup_indexes.php" script on the server unless you might need to add new indexes in the future. If you do add indexes, simply return this PHP script. New index tables will be added without affecting previously created indexes.
Specifying the index in "neodb_setting.php" is done using a PHP multi-dimensional array, and looks like this:
$NEODB_INDEXES = array( array ("DISPLAY","s","VARCHAR(50)"), array ("LEADER","i","INT") );
This creates two indexes, one called "DISPLAY" and the other called "LEADER". The format for the inner array is as follows:
In this example, two indexes are created:
Warning, it is advised that if you have big strings you should keep the number of items in your indexes small or if you have big indexes keep your strings small. Big strings with big indexes use a lot of I/O and will slow your searches down and may impact your network latency when finding a lot of rows.
You can have any number of indexes, but try to limit the number of indexes you update with your data small (2 or less). Each SAVE requires 2 logical IOs, one to test to see if the data exists, one to write out the changes. INDEXES require 2 logical IOs and having a lot of them slows your saves down dramatically.
Once an index is defined, you can write to it using C#:
aDescriptor.Index("DISPLAY",LastName + ", " + FirstName );
Running an aDescriptor.Index on an Index that does not exist will generate a failure. Similarly, if you reference an index that doesn't exist when doing a search, the system will generate a failure.
Dynamic Indexes are index that are created by the runtime environment and are always string indexes. While they were created to support specific game objects, they can be used exactly like a regular index for any purpose what-so-ever. The only difference is that index names must begin with "DYN_", so to create a dynamic index, you say:
_NEODB.ServerCreateDynamicIndex("DYN_INDEXNAME",CreationSuccess,ReportFailure);
Once you have the index name, you can use any of the index search methods, such as:
_NEODB.ServerFindEquals("DYN_INDEXNAME",NEODBSort.Ascending, "BOB", LoadSuccess, ReportFailure );
Dynamic Indexes have two additional methods (1) Delete the Dynamic Index _NEODB.ServerDeleteDynamicIndex("DYN_INDEXNAME",DeleteSuccess,ReportFailure); (2) Purge all the rows out of NEODB that are found in the index _NEODB.ServerPurgeDynamicIndex("DYN_INDEXNAME",PurgeSuccess,ReportFailure);