Skip to content
stanistan edited this page Apr 18, 2011 · 2 revisions

This is the select function that parses AQL and returns the query results.

Basic Usage

$aql = "
		artist {
		   name
		   where id = 10 
		}
	";
$rs = aql::select($aql);

Prases to this SQL

SELECT artist.name as "name", artist.id as "artist_id" FROM artist as artist WHERE artist.active = 1 AND artist.id = 10

It will return a nested row record array.

Array
(
	[0] => Array
		(
			[name] => Pink Floyd
			[artist_id] => 10
			[artist_ide] => BekjfoijeDZ
		)
)

Table idenitifer and an encrypted table identifier (IDE) is returned automatically with the results.

AQL assumes that each table has the field active. Instead of deleting records in a database, you can set active = 0 and it will return the same results.

Left Joins

artist_album {
	name as album_name
}
artist {
	name as artist_name
}

AQL will figure out joins automatically based on foreign keys in the table, but you can also write them explicitly.

artist_album {
	name as album_name
}
artist on artist_album.artist_id = artist.id {
	name as artist_name
}

Select DISTINCT and Aggregate Functions

For these types of queries, record identifiers will not be automatically added, so you may have to explicitly state them if you want them in the results.

distinct artist_album {
        id as artist_album_id,
	name as album_name
}
artist {
	name as artist_name
}

For aggregate functions in queries, the appropriate fields are added to the group by clause if they are not already there.

Clone this wiki locally