One purpose of this (abbreviated query language) is to generate SQL queries so that you don't have to repeat yourself.
artist {
name
}
Scoped SQL!
parse(statement).getSQL(); // select artist.name from artist
Default options.
var parser = new aql.Parser({
contraints: ['active', 1],
fields: function(table) {
return { id: table.name + '_id' };
}
});
select artist.id as artist_id, artist.name from artist where artist.active = 1
artist {
name
}
label on artist.id = artist_id {
label as label_name
}
select
artist.id as artist_id,
artist.name,
label.id as label_id,
label.name as label_name
from artist
left join label on artist.id = label.artist_id and label.active = 1
where artist.active = 1
var q = parse(statment);
q.getSQL({
where: {name: 'Pink Floyd'}
});
Generates:
select
artist.id as artist_id,
artist.name,
label.id as label_id,
label.name as label_name
from artist
left join label on artist.id = label.artist_id and label.active = 1
where artist.active = 1
and artist.name = 'Pink Floyd'