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:
Person.
"Retrieve all
instances of Person with the surname Smith"
allPersons select:
[ :each | each surname = 'Smith'].
"Are there any Persons with the name
'John Smith'? "
allPersons anySatisfy:
[ :each | (each firstName = 'John')
& (each surname = 'Smith')].
"Retrieve all Persons
not living in London, Birmingham or Manchester"
allPersons reject:
[ :each | #('London' 'Birmingham' 'Manchester') includes:
each address city].
"Retrieve any
Person living in the NW3 postal area"
allPersons detect:
[ :each | 'NW3*' match:
each address postcode]
ifNone: [nil].
"Find all Persons
born in 1970"
allPersons select:
[ :each | each dateOfBirth year =
1970].
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.