SQL
Introduction
The reference is your key to a comprehensive understanding of the Relay Class
<aside>
❗ This is very similar to what you will be doing in data structures. You need a good idea of how Object Oriented Programming works. I would suggest going over some of those concepts before you begin. You will need to search how SQL works before you begin work on this class.
</aside>
SQL Syntax
Purpose
This class offers all the methods that we need for interacting with the database. This is so that people coding the Relay and the relay container classes don’t have to worry about all the functionalities of a database. This is a little trick we call abstraction 👀
Functions
- Constructor: connects to the database, creates a cursor
- checkIfRelayExists: does what it says
- returns true if a relay with the id passed in exists, false if not
- addRelay: adds a relay to the database
- param id : int, state : bool
- raise a ValueError if another relay with the same id already exists
- getRelayState: Returns the state of a relay based on the passed in id
- param: id of the relay : int
- return the state of the relay : bool
- raises a value error if a relay with the id doesn’t exist
- dropRelay: drops/ removes a relay with the passed in id
- param id of the relay : int
- return true if the relay was successfully dropped
- updateRelayState: Updates the state of the relay with the passed in id
- param id : int, state : bool
- return true if the relay was successfully updated
- raise valueError if the relay does not exist
- getAllRelays: returns all relays in the database
- returns a list of all the relays in the database : list
Future Changes
No Future changes! The database is the deepest point in the rabbit hole that is a tech stack. But that also means that all other code depends on this!