Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor lecture TWP42: Bases de datos #193

Closed
AngelaRemolina opened this issue Aug 21, 2021 · 0 comments · Fixed by #200
Closed

Refactor lecture TWP42: Bases de datos #193

AngelaRemolina opened this issue Aug 21, 2021 · 0 comments · Fixed by #200

Comments

@AngelaRemolina
Copy link
Collaborator

This lecture has codeblocks for sqlite3 code instead of having an interactive activecode like other lectures. This is because Runestone does not support the sqlite3 library from python. Bython does not support it either.

Because of these reasons it is needed to find a way to use sqlite3 inside the book or replan this lecture in a way to teach with SQL.

By far there has been 3 attemps of refactoring the lecture, here they are order by closest to the solution:

  1. Using the activecode SQL languge from Runestone: SQL activecode approach #185
    Some configuration to use this SQL tool from Runestone must be done, because when you try to access the file surf.db, a CORS error shows up in console and nothing is shown. There might be something related with the book not being served by Runestone because in this error it tries to access to the db from an URL in runestone site: /runestone/books/published/PyZombis/_static/sql-wasm.wasm asuming that the book is published.

  2. Using sql.js library from javascript: Refactor lecture TWP42: Bases de datos (sql.js approach) #184
    This other option loads the database using the .. raw:html instruction from runestone.
    This is the best attempt since you need to find a way to access to the global javascript variable db from the brython activecode block. Enter this PR for more detail, but if you call db in browser console you can see the database.

  3. With indexedDB: Refactor Lecture TWP42: Bases de datos (indexedDB approach) #171
    This aproach works, but the syntax changes a lot from the original lecture where sqlite3 was used.

For example:

cursor.execute("select * from surfers  where age > 25")
linhas = cursor.fetchall()
for linha in linhas:
    print("id :",linha['id'])
    print("Nombre :",linha['name'])
    print("Pais  :",linha['country'])
    print("Media  :",linha['average'])
    print("Estilo :",linha['board'])
    print("Edad  :",linha['age'])
    print()

had to change to:

if(getattr(v, "edad") >=25):
    for key in ["nombre", "pais", "media", "estilo", "edad"]:
        print(f"{key}: {getattr(v, key)}")
  getattr(res, "continue")()

It is not a friendly syntax for new students that are learning this for the first time.

reingart added a commit that referenced this issue Mar 24, 2022
mdelgadonyc pushed a commit to mdelgadonyc/PyZombis that referenced this issue Apr 26, 2023
mdelgadonyc pushed a commit to mdelgadonyc/PyZombis that referenced this issue Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant