U is Update

From Onix OS Wiki
Jump to: navigation, search

The method used to change the data that has already been created or created. The purpose here is to update only the data or change the data with a match.


update(modeldef, {values and keys...}, {values and keys...})

Three things are important to update. You need the model to have hash of the data you are updating and to have it updated according to what you are updating. In other words, the hash defined here is true instead of "where".


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

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

create(payment, {
	"user_id": 1,
	"money": 100,
	"currency": "$"
	#....other information

update(payment, {"user_id":1}, {"money": 200})

In the example, we updated the database because we created a data with the model and made a mistake in the data. In the price table, the price for the user from 100 to 200 we have taken.