Offers a wrapper around file or database I/O for simple data needs. You’ll be able to access the data without caring what the backend is (SQL or flat-file), but each row in the table will need to have an unique, primary key and only four operations are supported on the data. The four operations are fetch all rows (otlib.DataTable.GetAll), retrieve row by key (<otlib.DataTable.Fetch), delete row by key (<otlib.DataTable.Remove), and update row (which will happen automatically unless you’re doing transactions). In other words, there’s no searching on anything other than the unique, primary key unless you’re willing to grab all the data (otlib.DataTable.GetAll) and search yourself (but that would be extremely slow).
Simple Data | Offers a wrapper around file or database I/O for simple data needs. |
otlib | |
preferred_database_type | The DatabaseTypes to use by default. |
CreateDataTable | Creates a new data table for use. |
otlib. | |
AddKey | Adds a key to the data table. |
AddListOfKeyValues | Adds a key to the data table, whose value is going to be a table. |
BeginTransaction | Begins a transaction. |
EndTransaction | See BeginTransaction. |
ClearCache | Clears any cache that may be built up in this datatable. |
DisableCache | First clears the cache with ClearCache and disables further caching until re-enabled with EnableCache. |
EnableCache | See DisableCache. |
UntrackedCopy | One of the downsides of using DataTable is that data you get out of it (except GetAll) can’t be thrown throw an iterator like pairs because of the way we track changes to the table. |
ConvertTo | Convert the DataTable from using one database type to another. |
Insert | Insert (or replace existing with) a new row. |
Fetch | Fetch a row from the database. |
Remove | Delets a row from the database. |
GetAll | Fetchs all rows from the database. |
Empty | Empties all existing data for this database and clears any caches. |
preferred_database_type | The DatabaseTypes to use by default. |
CreateDataTable | Creates a new data table for use. |
preferred_database_type
The DatabaseTypes to use by default.
function CreateDataTable( table_name, primary_key_name, primary_key_type, comment, database_type )
Creates a new data table for use.
table_name | The unique string of the table name. IE, “users” for data about users. |
primary_key_name | The string of the name for the primary key of the table. IE, “ip_address”. For more information see DataTable.AddKey. |
primary_key_type | The string of the type for the primary key of the table. For more information see DataTable.AddKey. |
comment | The optional string of the comment to use for the primary key. |
database_type | The optional otlib.DatabaseTypes to use for this table. Defaults to the value of preferred_database_type. |
The newly created DataTable.
v1.00 | Initial. |
AddKey | Adds a key to the data table. |
AddListOfKeyValues | Adds a key to the data table, whose value is going to be a table. |
BeginTransaction | Begins a transaction. |
EndTransaction | See BeginTransaction. |
ClearCache | Clears any cache that may be built up in this datatable. |
DisableCache | First clears the cache with ClearCache and disables further caching until re-enabled with EnableCache. |
EnableCache | See DisableCache. |
UntrackedCopy | One of the downsides of using DataTable is that data you get out of it (except GetAll) can’t be thrown throw an iterator like pairs because of the way we track changes to the table. |
ConvertTo | Convert the DataTable from using one database type to another. |
Insert | Insert (or replace existing with) a new row. |
Fetch | Fetch a row from the database. |
Remove | Delets a row from the database. |
GetAll | Fetchs all rows from the database. |
Empty | Empties all existing data for this database and clears any caches. |
function DataTable:AddKey( key_name, key_type, comment )
Adds a key to the data table. To help understand this, imagine that you couldn’t just do my_table.my_key = some_value in lua, that you had to define my_key first before you were able to assign to it. That’s basically what this function is for. You’ll need to define any keys you want to use before you use them.
This function must be used directly after you create the table using CreateDataTable and before you use functions such as Insert or Fetch.
key_name | The string of a key name for the table. IE, “group”. This name is what you’ll use to refer to the data later. |
key_type | The string of the type for this key in the table. Valid strings to pass in are “string(<max_length_of_string)” or “number”. |
comment | The optional string of the comment to use for this key. The comment will show up in flatfiles and in MySQL. |
Self.
v1.00 | Initial. |
function DataTable:AddListOfKeyValues( list_name, key_type, value_type, comment )
Adds a key to the data table, whose value is going to be a table. To help understand this, imagine that you couldn’t just do my_table.my_key = {} in lua, that you had to define my_key first before you were able to assign a table to it. That’s basically what this function is for. You’ll need to define any keys you want to use before you use them.
In this case, the value of the key defined here is a table that can contain anything, as long as each key and value in the table conform to the types given, below.
This function must be used directly after you create the table using CreateDataTable and before you use functions such as Insert or Fetch.
list_name | The string of a list name for the table. IE, “allow”. This name is what you’ll use to refer to the data later. |
key_type | The string of the type for the keys in the list. See AddKey for more information. |
value_type | The string of the type for the values in the list. See AddKey for more information. |
comment | The optional string of the comment to use for this key. The comment will show up in flatfiles and in MySQL. |
Self.
v1.00 | Initial. |
function DataTable:BeginTransaction()
Begins a transaction. Between beginning and ending a transaction, data is basically built up in a buffer before getting sent off. This is especially useful for flatfiles since it means that we won’t have to save the file (which is slow) a thousand times when data is initialized if the initialization takes advantage of transactions.
You should note that not all implementations support transactions though, so this function might be silently ignored.
v1.00 | Initial. |
function DataTable:DisableCache()
First clears the cache with ClearCache and disables further caching until re-enabled with EnableCache. Flatfiles are a bit of a special case in that disabling the cache won’t force the file to be re-read every time we need to fetch data.
v1.00 | Initial. |
function DataTable:UntrackedCopy( data )
One of the downsides of using DataTable is that data you get out of it (except GetAll) can’t be thrown throw an iterator like pairs because of the way we track changes to the table. To help alleviate this problem, you can create an untracked copy of the data using this function.
data | The table of the data you want to get an untracked copy of. Must directly be the table you got from Insert or Fetch. Don’t pass anything else in here. |
The copied, untracked table.
v1.00 | Initial. |
function DataTable:ConvertTo( database_type )
Convert the DataTable from using one database type to another. Before converting the data to the new database type, it completely wipes whatever information was in the destination database type, so make sure you’re okay with losing whatever information may be there.
database_type | The destination otlib.DatabaseTypes. |
Self.
v1.00 | Initial. |
function DataTable:Insert( primary_key, data )
Insert (or replace existing with) a new row.
primary_key | The primary key for the new row, should be the same type as you declared it to be in CreateDataTable. |
data | An optional table of data to constitute this row. Whatever information is required that isn’t present in this table will be added by the function. Defaults to {}. |
The table that constitutes the tracked, inserted row. Use this new value to modify data.
v1.00 | Initial. |
function DataTable:Fetch( primary_key )
Fetch a row from the database.
primary_key | The primary key for the new row, should be the same type as you declared it to be in CreateDataTable. |
The table that constitutes the tracked, inserted row if it exists, nil if it doesn’t.
v1.00 | Initial. |
function DataTable:Remove( primary_key )
Delets a row from the database.
primary_key | The primary key for the new row, should be the same type as you declared it to be in CreateDataTable. |
A boolean, true if it existed and was removed, false if the row didn’t exist.
v1.00 | Initial. |
function DataTable:GetAll()
Fetchs all rows from the database. This is similar to Fetch, except that it fetches all rows in the entire database, and all returned data is untracked. This obviously pretty slow and should only be used if absolutely necessary.
The table that constitutes the entire database.
v1.00 | Initial. |
The DatabaseTypes to use by default.
preferred_database_type
DatabaseTypes
Creates a new data table for use.
function CreateDataTable( table_name, primary_key_name, primary_key_type, comment, database_type )
Adds a key to the data table.
function DataTable:AddKey( key_name, key_type, comment )
Adds a key to the data table, whose value is going to be a table.
function DataTable:AddListOfKeyValues( list_name, key_type, value_type, comment )
Begins a transaction.
function DataTable:BeginTransaction()
See BeginTransaction.
function DataTable:EndTransaction()
Clears any cache that may be built up in this datatable.
function DataTable:ClearCache()
First clears the cache with ClearCache and disables further caching until re-enabled with EnableCache.
function DataTable:DisableCache()
See DisableCache.
function DataTable:EnableCache()
One of the downsides of using DataTable is that data you get out of it (except GetAll) can’t be thrown throw an iterator like pairs because of the way we track changes to the table.
function DataTable:UntrackedCopy( data )
Fetchs all rows from the database.
function DataTable:GetAll()
Convert the DataTable from using one database type to another.
function DataTable:ConvertTo( database_type )
Insert (or replace existing with) a new row.
function DataTable:Insert( primary_key, data )
Fetch a row from the database.
function DataTable:Fetch( primary_key )
Delets a row from the database.
function DataTable:Remove( primary_key )
Empties all existing data for this database and clears any caches.
function DataTable:Empty()