Talking Queries



( ZN >= 5.2.0

These uses are intended to make query usage more meaningful and short . You can write easier and more meaningful queries especially for CRUD operations. Method writings have case sensitivity . Detailed examples of the use of these queries will be given below.

 

 

# Result Operations


It is a kind of use of DB :: result () method.

Rule
Object tablenameResult ( String $ output = 'object' )
uses

To get all the results of the blog table;

$result = DB::blogResult();

To get results according to a run;

$result = DB::whereSlug('example-data')->blogResult();

To get results according to more than one run;

$result = DB::whereSlugAnd('example-data')->whereId(10)->blogResult();

 

 

# Row Operations


It is a kind of use of DB :: row () method.

Rule
Object tablenameRow ( Mixed $ output = 0 )
uses

To get a single row of the blog table;

$row = DB::blogRow();

To get the result of the 5th entry of the blog table ;

$row = DB::blogRow(4);

To get single line results according to a certain run;

$row = DB::whereId(5)->blogRow();

 

 

# Value Operations


It is a kind of use of DB :: value () method.

Rule
scaler tablenameRowKolonname ( Void)
uses

To get a single column value for the blog table;

$value = DB::blogRowSlug();

To get a single column value of the blog table according to a certain run;

$value = DB::whereIdOr(1)->whereIdOr(10)->whereId(20, '<')->blogRowName();

If the condition is a comparison other than equilibrium, the comparison operator to the second parameter is specified.

$value = DB::whereCreate_date('2017', '<')->blogRowContent();

 

 

# Join Operations


DB :: typeJoin () is a kind of use of methods. In this method, they refer to the types: left, right.

Rule
this leftJoinTablenameColumnnameTablename2Columnname2 ( String $ operator = '=' )
uses
$result = DB::leftJoinAccoutsIdCommentsUser_id()
            ->rightJoinCommentsUser_idTopicUser_id('!=')
            ->commentsResult();
SELECT * FROM comments
LEFT JOIN accouts ON accouts.id = comments.user_id
RIGHT JOIN comments ON comments.user_id! = Topic.user_id 

 

 

# Group By and Order By Transactions


It is a kind of use of DB :: groupBy () and DB :: orderBy () methods.

Rule
this groupByColumnname ( Void)
this orderByColumnnameOrdertype ( Void)
uses
DB::orderByCreate_dateAsc()->groupByCreate_date()->productsResult();
SELECT * FROM products GROUP BY create_date ORDER BY create_date Asc

 

 

# Insert Operation


It is a kind of use of DB :: insert () method.

Rule
Bool tablenameInsert ( Array $ columnAndValues )
uses

To add a new entry to the blog table;

DB::blogInsert(['name' => 'New Blog', 'content' => 'New Blog Content']);

 

 

# Update Operation


It is a kind of use of DB :: update () method.

Rule
Bool tablenameUpdate ( Array $ columnAndNewValues )
uses

To update a blog's blog entry;

DB::blogUpdate(['name' => 'New Blog 2']);

 

 

# Delete Operation


It is a kind of use of DB :: delete () method.

Rule
Bool tablenameDelete ( Void )
uses

To delete a record of the blog table;

DB::whereName('New Blog 2')->blogDelete();

 

 

# Create Table Operation


It is a kind of use of DBForge :: createTable () method.

Rule
Bool tablenameCreate ( Array $ columnsAndProperties )
uses

To create an Accounts table;

DBForge::accountsCreate(['id' => [DB::int(11), DB::autoIncrement(), DB::primaryKey()]]);

 

 

# Drop Table Operation


It is a kind of use of DBForge :: dropTable () method.

Rule
Bool tablenameDrop ( Void)
uses

To delete the Accounts tab;

DBForge::accountsDrop();

 

 

# Truncate Operation


It is a kind of use of DBForge :: truncate () method.

Rule
Bool tablenameTruncate ( Void)
uses

To empty the contents of the Accounts table;

DBForge::accountsTruncate();

 

 

# Rename Operation


It is a kind of use of DBForge :: renameTable () method.

Rule
Bool tablenameRename ( String $ newTableName )
uses

To change the name of the Accounts table;

DBForge::accountsRename('new_accounts');