Coder Social home page Coder Social logo

python-p3-translating-from-orms-to-sqlalchemy-lab's Introduction

Translating from ORMS to SQLAlchemy Lab

Learning Goals

  • Use an external library to simplify tasks from earlier ORM lessons.
  • Use SQLAlchemy to create, read, update and delete records in a SQL database.

Key Vocab

  • Schema: the blueprint of a database. Describes how data relates to other data in tables, columns, and relationships between them.
  • Persist: save a schema in a database.
  • Engine: a Python object that translates SQL to Python and vice-versa.
  • Session: a Python object that uses an engine to allow us to programmatically interact with a database.
  • Transaction: a strategy for executing database statements such that the group succeeds or fails as a unit.
  • Migration: the process of moving data from one or more databases to one or more target databases.

Instructions

This is a test-driven lab. Run pipenv install to create your virtual environment and pipenv shell to enter the virtual environment, then cd into the lib/ directory. Run pytest -x to run your tests. Use these instructions and pytest's error messages to complete your work in the lib/ folder.

The testing file for this lab will execute many of the same tests as "Putting it All Together: ORMs Lab" from the previous Canvas module. There are nine tests in total: one for your data model in lib/models.py and eight for your functions in lib/dog.py. In the previous lab, you had to write quite a bit of code to get those tests passing- using SQLAlchemy, it should be much easier.

Tips and Tricks

  • The bodies of all functions in dog.py except create_table() and save() should be composed of a single line of code.
  • Read through the pytest error messages to make sure the input and output for your functions match the tests.
  • Remember which attributes are required when designing a SQLAlchemy data model: a __tablename__, a primary_key, and one or more Columns.

Once all of your tests are passing, commit and push your work using git to submit.


Resources

python-p3-translating-from-orms-to-sqlalchemy-lab's People

Contributors

ianstrom avatar jilliankim avatar jlboba avatar lizbur10 avatar pgill97 avatar professor-ben avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-p3-translating-from-orms-to-sqlalchemy-lab's Issues

Passing tests without using given args

Canvas Link

https://learning.flatironschool.com/courses/6049/assignments/209225?module_item_id=482537

Concern

Couple of things here that could be confusing for students:

  • I'm able to pass the final test without having to use the dog argument.
  • The new_from_db function starter code only has one argument of session being passed in, but on initial run of the tests, it says that it expects 2 args, but only received one. Should the starter code for this function also include the second argument like the other functions in this lab? I could see how this could be confusing for students if they were coming in thinking that most of the arguments are made for them.
  • Should there be any mention that they would need to import Dog from models? Maybe including a hint or a reminder that they would need to do so could help with this.

Just some thoughts.

Additional Context

No response

Suggested Changes

No response

Getting Started Instructions

Canvas Link

https://learning.flatironschool.com/courses/6049/assignments/195260?module_item_id=439018

Concern

When the instructions inform a student to start work with canvas instructions and test feedback it tells the student to complete work in the lib file when the repository has an app file.

Additional Context

I envision students looking for a lib file and not finding it and not sure of what to do (event though the working python files in lib and app are the same).

Suggested Changes

I would change the instructions in the canvas lesson/read.me from lib to app.

Arguments for tests need to be revisited

Canvas Link

https://learning.flatironschool.com/courses/6329/assignments/239716?module_item_id=563719

Concern

The create_table() test passes an engine argument that isn't in the templated function. had to add the engine argument in to get the test to pass. The lab specifically says the function body for this test should be composed with more than one line of code, but once you add the engine argument, you pass the test with only one line

the update_breed() template function in dog.py includes a dog argument that is unused

Additional Context

No response

Suggested Changes

No response

new_from_db solution

Canvas Link

https://learning.flatironschool.com/courses/6049/assignments/209225?module_item_id=482537

Concern

The solution to the new_from_db method seems a little odd to me. My impression is that it simply grabs and returns the first row in the database, and that's all it can do. However, the instructions in the tests make it seem like it should be used in a more general manner - takes a database row and creates and returns a dog instance.

Furthermore, does it even make sense to include this method in this lab? Doesn't the use of SQLAlchemy mean that we don't actually need this "new from db" method since we can use .all, .first, or a list comprehension in conjunction with a query to convert our query results into python objects?

I understand that the idea is to rewrite the same methods from the previous ORMs lab to demonstrate the difference, but I think the inclusion of this method is a little misleading / confusing. It might be more helpful to deliberately skip this method and talk about why it's been skipped - i.e., that using SQLAlchemy makes this method unnecessary. The current solution doesn't really seem like it illustrates any important concept other than how to pass this test. I could be missing something important though! Thanks!

Additional Context

No response

Suggested Changes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.