ReStore includes a sophisticated querying system, which allows
you to retrieve any object or set of objects that you have previously stored.
The ReStore message instancesOf:
returns a Collection-like object representing all instances of the given class
in the database. You may then use standard Smalltalk enumeration methods - these
are automatically translated into SQL queries, retrieving only the matching objects. This results in very efficient querying, since the vast majority of
objects are not brought into memory. Some examples:
allPersons := aReStore instancesOf:
instances of Person with the surname Smith"
[ :each | each surname = 'Smith'].
"Are there any Persons with the name
'John Smith'? "
[ :each | (each firstName = 'John')
& (each surname = 'Smith')].
"Retrieve all Persons
not living in London, Birmingham or Manchester"
[ :each | #('London' 'Birmingham' 'Manchester') includes:
each address city].
Person living in the NW3 postal area"
[ :each | 'NW3*' match:
each address postcode]
"Find all Persons
born in 1970"
[ :each | each dateOfBirth year =
The last example highlights one of the advanced features of the ReStore
querying system - the ability to translate Smalltalk messages (in this case year)
into SQL functions. This facility is provided by the SQLDialect object, and so
can be customised and extended to take advantage of the different functions
provided by your chosen database. Translating messages to functions in this way transfers more of
the work from your Smalltalk application to the database server, reducing the
amount of data transferred and making your application even more efficient.