Skip to content

Latest commit

 

History

History
129 lines (110 loc) · 6.58 KB

Joins.wiki

File metadata and controls

129 lines (110 loc) · 6.58 KB

  1. summary How to perform JOINs between IndexedCollections
  2. labels Featured
Although it is often easier and more performant to de-normalize data, it is possible with CQEngine to perform JOINs and SQL EXISTS-type queries between `IndexedCollection`s at runtime with reasonable performance (at least, outperforming external databases).

<wiki:toc max_depth="2"></wiki:toc>

SQL EXISTS

Given a collection of Cars, and a collections of Garages, find cars which are convertible or which have a sunroof, which can be serviced by garages in a particular city. Source code of this example here.

The example above prints:

Ford Focus has a sunroof or is convertible, and can be serviced in Dublin
BMW M3 has a sunroof or is convertible, and can be serviced in Dublin

SQL EXISTS-based JOIN

Given a collection of Cars, and a collections of Garages, find cars which are convertible or which have a sunroof, which can be serviced by garages in a particular city, along with the names of those garages. Source code of this example here.

The example above prints:

Ford Focus has a sunroof or is convertible, and can be serviced in Dublin at the following garages:- 
---> Garage{garageId=4, name='Jill's garage', location='Dublin', brandsServiced=[Ford Focus]}
---> Garage{garageId=3, name='John's garage', location='Dublin', brandsServiced=[Ford Focus, Ford Taurus]}

BMW M3 has a sunroof or is convertible, and can be serviced in Dublin at the following garages:- 
---> Garage{garageId=2, name='Jane's garage', location='Dublin', brandsServiced=[BMW M3]}