Introduction
Methods of CRUD may sound familiar to you, but most of us find web2py as alien in our world. So, let us start by addressing the elephant in the house “web2py”.web2py is the free, open-source web framework. It is a full-stack web framework used to develop highly secure, data-driven web pages. And where there is data, CRUD plays an important role. So, aren’t you interested in learning about the different CRUD methods in web2py? Let us discuss the methods of CRUD in detail.

Methods of CRUD
Managing and updating data is an important part of the software industry. We do it by the four basic operations: create, read, update and delete, and the acronym CRUD simply represents it. We need to learn about the methods of CRUD so that we can use these operations effectively and manage data-driven applications in the software world.
Let us now see the signatures of methods of CRUD in web2py.

crud.tables()
crud.create(table, next, onvalidation, onaccept, log, message, formname, **attributes)
crud.read(table, record)
crud.update(table, record, next, onvalidation, onaccept, ondelete, log, message, deletable)
crud.delete(table, record_id, next, message)
crud.select(table, query, fields, orderby, limitby, headers, **attr)
crud.search(table, query, queries, query_labels, fields, field_labels, zero, showall, chkall)
Let us look at the following meanings of the terms used in the above piece of code.
-
The table is either a DAL table or the name of the table the procedure should use.
-
The ids of the records that the method should operate on are record and record id.
-
The URL to redirect to the following success is then given. The id of the record that is now being created or edited will be used in place of the substring "[id]" if the URL contains it (use URL(..., URL encode=False) to prevent the brackets from being escaped).
-
The function of onvalidation is identical to those of FORM and SQLFORM.
-
Before redirection, but after the form submission is accepted and handled, a function called onaccept should be invoked. The form will be supplied as an argument when this is called.
-
Log is the message in the log. Variables of the form are seen in log messages for CRUD.
-
Dictionary terms like "percent (id)s" (the message actually logged is log percent form.vars).
-
When a form is accepted, a flash message appears. **attributes add more dreck to the attribute. Arguments for the update keyword to be supplied to the function Object() { [native code] } of the SQLFORM.
-
When a record is deleted using an "update" form, ondelete is invoked rather than onaccept.
-
Deletable controls whether a delete option should be available on the "update" form
-
The search term to be used to choose records is the query.
-
Fields is a list of available fields.
-
The order in which records should be chosen is determined by orderby
-
limitby chooses which entries from a certain range should be shown
- A dictionary called headers that is given to the SQLTABLE function Object() { [native code] } maps field names into header names searches a list like ['equals', 'not equal', 'contains'] that includes the permitted search techniques.
Let us now look at an example of usage in a single controller function.
Example of usage in the single controller function
## assuming db.define_table('person', Field('name'))
def people():
form = crud.create(db.person, next=URL('index'),
message=T("record created"))
persons = crud.select(db.person, fields=['name'],
headers={'person.name': 'Name'})
return dict(form=form, persons=persons)
Here is another very generic controller function that lets you search, create and edit any records from any table where the table name is passed in the request.args(0):
def manage():
table = db[request.args(0)]
form = crud.update(table, request.args(1))
table.id.represent = lambda id, row: \
A('edit:', id, _href=URL(args=(request.args(0), id)))
search, rows = crud.search(table)
return dict(form=form, search=search, rows=rows)
The line table is visible. id.represent=... instructs web2py to display a link to the website rather than the actual text of the ID field and passes the ID as request. The new page becomes an update page when args(1) is used.
In the next section, we will be discussing the recording versions in web2py using CRUP operations.






