Skip to content

SQLiteManager: Insert Update Delete

Raphael Winkler edited this page May 29, 2022 · 1 revision

Inserting and updating rows

Inserting and updating your data couldn't be easier! Simply call "SaveToDatabase()" on your object (in this example our "User" class). This method of saving has two advantages:

  • Takes care of deciding on whether to INSERT or UPDATE
  • Child items (Lists) are also inserted/updated in the database
User user = new User()
{
	Guid = Guid.NewGuid().ToString(),
	Name = "John Doe",
	Birthday = DateTime.Now,
	Password = "Abc123"
};

user.SaveToDatabase(); // If this user wasn't loaded from database, it gets inserted. If this user comes from the database, it is updated instead

Deleting existing rows

Like saving or loading database entries, it's also very easy to delete existing data. By calling "DeleteFromDatabase()" on a DatabaseEntry you remove it from the database.

User user = User.LoadFromDatabase(new Condition("name", "John Doe"));

user.DeleteFromDatabase(); // Removes the user "John Doe" from the database