IntermediateAbout 20 min

    Query Languages & Data Models

    Read the full article on Substack

    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)
    1Great whiteshark
    2Mantaray
    3Orcadolphin
    4Stingrayray
    5Hammerheadshark
    6Bottlenosedolphin
    7Belugawhale
    8Sea otterotter

    Same question, two styles: which animals are sharks? First, a loop that says how to look.

    1/15

    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

    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 here

    Declarative query

    Drop items here
    6 pieces left to place

    Quiz

    10 questions
    Question 1 of 10
    Score: 0

    What does a declarative query specify?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going