def spanner_get_pets()

in courses/understanding_spanner/cloud-functions/spanner_get_pets/main.py [0:0]


def spanner_get_pets(request):
    query = """SELECT OwnerName, PetName, PetType, Breed 
         FROM Owners 
         JOIN Pets ON Owners.OwnerID = Pets.OwnerID;"""

    outputs = []
    with database.snapshot() as snapshot:
        results = snapshot.execute_sql(query)
        output = '<div>OwnerName,PetName,PetType,Breed</div>'
        outputs.append(output)
        for row in results:
            output = '<div>{},{},{},{}</div>'.format(*row)
            outputs.append(output)

    return '\n'.join(outputs)