-
Notifications
You must be signed in to change notification settings - Fork 0
SQLiteManager v1.0: Getting started
Raphael Winkler edited this page May 29, 2022
·
1 revision
First of all you'll need the dependency. You can either
- Pull it from NuGet (recommended):
Install-Package TastyApps.Core.SQLiteManager -Version 1.0.3
- Pull from GitHub packages:
dotnet add PROJECT package TastyApps.Core.SQLiteManager --version 1.0.3
- Download and build this repository yourself download and build this repository yourself or pull it from NuGet (recommended):
Before you can work with your database you need to set it up. The best way to initialize your database is by creating a separate, static class containing your database structure.
In this example we'll call our class "DatabaseStructure"
class DatabaseStructure
{
public readonly TableDescriptor users;
// We need a list of all tables to initialize the database later on
public readonly List<TableDescriptor> tables;
public DatabaseStructure()
{
List<IColumn> columns_users = new List<IColumn>()
{
// The object type inside <> tells the table which type to use
// First variable is the column name, the second variable table can be used to set column modes
new ColumnsDescriptor<int>("ID", ColumnMode.PRIMARY_KEY),
new ColumnsDescriptor<string>("name", ColumnMode.NOT_NULL),
new ColumnsDescriptor<string>("information"),
new ColumnsDescriptor<string>("email")
};
// First variable sets the table name, second variable is a list of columns
users = new TableDescriptor("users", columns_users);
// Add all your tables to the list
tables = new List<TableDescriptor>()
{
users
};
}
}
Now we just need to initialize the database:
DatabaseStructure structure = new DatabaseStructure();
Database.Initialize("users.db", structure.tables);
This will create all defined tables and update itself depending if you add or remove columns or tables.
Next up: Defining foreign keys
-
Home
- Tasty.Logging
-
Tasty.SQLiteManager
- SQLiteManager 2.0 and up:
- SQLiteManager 1.0.3 and below:
- Tasty.ViewModel