D is Delete

From Onix OS Wiki
Jump to: navigation, search

It is the method used to delete data in a simple sense. Connects and deletes data to the model.

Definition

def resultdef = (delete(modeldef, {....keys and values}))

As with other functions, two methods are required to erase the data. These methods are the name of the model and the hash definition needed to find the data to be deleted. The hash definition replaces "where" and finds and deletes the data.

Example

def db = (database("sqlite3","sqlite_database_example.db"))

def payment = (model(db, "payments", {
	"user_id": "int",
	"money": "int",
	"currency": "text",
	"datetime": "DATETIME",
	"duedate": "DATETIME"
}))

def deleted = (delete(payment, {"id": 1}));

if (deleted){
	show("Payment 1 deleted.")
}

In the example, we re-create the payments model and connect it to the database. Then we erased the first data. We used an identifier to check if it was deleted, and we checked the situation. When it was deleted, we let him show us a message automatically.