tinyCampaign Query

When using the tinyCampaign (tinyC) query functions, you don’t need to know SQL (Structured Query Language). If you do know SQL, then great but if not, you only need to familiarize yourself with the different query functions that can be used..

The first thing you must understand about querying the database is that you must call the app’s global scope. For example if you are using a query in a custom function, then you need to call the $app’s global scope which can be called in one of two ways:

Or

The first example is the preferred and recommended way to call the app’s global scope.

Now that you have access to the $app global scope, you need to append that with the connection to the database:

Once you create a connection to the database, you can start building your query. All the information that follows should help you with writing the queries you need.

Table

Connect to a database table by calling the table() method.

An alternative to above is calling the database table name as a method.

Insert

When calling the insert(array $data) method, $data can be passed as a dimensional array to insert a new record.

Update

Save

Save() is a shortcut to insert() or update().

Insert

Update

Delete

Count

Count all the entries based on where() clause.

Use count for a specific column name.

Max

Max based on where() clause.

Min

Min based on where() clause.

Sum

Sum based on where() clause.

Avg

Average based on where clause.

Aggregate

FindOne

Returns a single record is found otherwise it will return false.

You can achieve the same above by using only the primary key and dropping the where clause.

Retrieving the entry.

Find

Find returns an ArrayIterator of rows found, otherwise it will return false.

Find also accepts a closure ( find(Closure $callback) ) to perform data manipulation.

Select

Select All

Select Columns

Where

Where can be used to setup the where clauses and they work with find(), findOne(), update(), and delete(). This is the same for the where aliases as well.Repetitive call to where and it’s aliases will append to each other using the AND ( _and_() )operator. Use _or_() to mimic the OR operator.

Examples

Aliases

There where aliases can help shorten the where examples above.

Primary key

Not Equal To

Like

Not Like

Greater Than

Greater Than Equal To

Less Than

Less Than Equal To

Where In

Where Not In

Where Null

Where Not Null

Where with OR and AND

Use _and_() / _or_() chained to any where clauses.

_and_()

_or_()

Order, Group, Limit, Offset

Joins

 

 

Was this article helpful?