Query Languages & Data Models
9 min read.
Compare a loop with a declarative query, a document with a shared row, a graph pattern, Datalog rules and a SPARQL triple query, each run step by step on a tiny data set.
Think of it this way: A loop is like giving a driver every turn. A declarative query is like giving only the address: the driver, or the GPS, picks the route and can change it when there is a jam.
rows read: 0
sharks = []
for row in animals:
if row.family == 'shark':
sharks.append(row)Same question, two styles: which animals are sharks? First, a loop that says how to look.
Check your understanding
Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.
Imperative or declarative?
Sort each trait into the style of query it describes.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
Imperative loop
Drop items hereDeclarative query
Drop items hereQuiz
10 questionsWhat does a declarative query specify?
Done with this lesson?
Sign in free to keep your progress, streak and quiz scores.