Introduction
The main advantage of web2py is thought to be the Database Abstraction Layer (DAL). The DAL makes the underlying SQL syntax available through a simple Applications Programming Interface (API).

We will learn about the more complex uses of DAL in this blog, such as creating effective tags-based search queries and hierarchical category trees.
The Data Abstraction Layer
(DAL)
You'll probably find that web2py is among the easiest frameworks to set up, understand, and use because it greatly emphasizes productivity and ease of use. However, it also has a tonne of functions and provides a tonne of power and flexibility. The DAL (Data abstraction layer) is one of the most essential features of the web2Py. Some of its important features are listed below.
Database Abstraction Layer (DAL), a feature of web2py, is an API that converts Python objects into database objects. Queries, tables, and records are all examples of database objects.
It is not necessary for a developer to compose an entire SQL query because the DAL dynamically constructs the SQL in real-time using the database back end's predefined dialect.
The primary benefit of adopting DAL is the portability of the applications with many types of databases.
Let’s move on to understanding the implementation of DAL.
Implementation of DAL
A database connection is needed by the majority of web2py apps. Therefore, the first stage in the design of an application is to create the database model.
Take the below-implemented program "helloWorld" as an example. The application's Models are where the database is implemented. The file models/db.custom.py contains all of the models for the specific application.
The data flow in Web2Py is shown below, and later we will see the steps for implementing the DAL.

Steps for Implementing DAL
Step1- The DAL Constructor
Establish a connection to a database. This is made via the DAL function Object(), also known as the DAL object.
dBase = DAL ('sqlite://storage.sqlite')
DAL's significant characteristic is that it permits many connections to the same database, to other databases, or even to databases of a different type. This line is found to be present in the models/db.py file. Therefore, unless you deleted it or needed to connect to a new database, you might not require it. Web2py connects by default to an SQLite database found in the file storage.sqlite.
The databases folder for the application contains this file. If the file is missing, web2py creates it when the program is initially launched.
SQLite saves all the data in a single file and is quick. This indicates that moving your data between applications is simple. In actuality, web2py packages the SQLite database(s) along with the applications. It offers total SQL functionality, including joins, aggregates, and translations.
With all those exciting features, some issues are also there in SQLite. Let's look at them.
One of them is that it does not enforce column types, and the only way to ALTER TABLE is to add or remove columns.
The additional drawback is that any transaction requiring write access locks the entire database.
Step2- Table Constructor
The define_table method can be used to define new tables once the database connection has been made.
dBase.define_table('invoice',Field('name'))
Table constructors likewise employ the approach mentioned above. The table constructor uses the same syntax. The table name is the first argument, and then a list of Field (s). The field constructor accepts the following arguments.

Adding to it, the define_table method also takes these three named arguments,
dBase.define_table('....',migrate=True, fake_migrate=False, format = '%(id)s')
migrate = True, If the table doesn't already exist, web2py is told to create it; if it doesn't meet the model description, it's told to change it.
If the model matches the content of the database table, set fake_migrate = True, which aids web2py in rebuilding the data.
format = "% (id)s", This format string specifies how records in the specified table should be displayed.





