-
Notifications
You must be signed in to change notification settings - Fork 2
Writing Your Own Data Adapters
Since TINA-ORM only comes with built in support for a limited amount of databases and your favorite database might not be one of them, Tina allows you to easily create a data adapter that you can use.
A data adapter is, in fact, a configuration class that inherits TinaConfig
and defines a simple operation - creating a table that conforms to a constant schema if it does not exist. Everything else is encapsulated in the core Tina
class.
The data adapter does this by overriding the CreateTableIfNotExists
method. For example, here's how the MySql
adapter does it.
public override void CreateTableIfNotExists()
{
const string createTable =
@"CREATE TABLE IF NOT EXISTS Tina
(
id INT AUTO_INCREMENT UNIQUE PRIMARY KEY,
Type VARCHAR(4000) CHARSET utf8,
Contents VARCHAR(4000) CHARSET utf8
);";
using (var conn = Connection)
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = createTable;
cmd.ExecuteNonQuery();
conn.Close();
}
}
The schema is, always, a three column table - id, Type and Contents. id is the primary key and is an auto incrementing integer. Type and Contents are both variable length Unicode strings.