forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3417b19
commit 950c294
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.DS_Store | ||
__pycache__/ | ||
*.pyc | ||
|
||
# Video Scripts | ||
s.txt | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
class Employee: | ||
"""A sample Employee class""" | ||
|
||
def __init__(self, first, last, pay): | ||
self.first = first | ||
self.last = last | ||
self.pay = pay | ||
|
||
@property | ||
def email(self): | ||
return '{}.{}@email.com'.format(self.first, self.last) | ||
|
||
@property | ||
def fullname(self): | ||
return '{} {}'.format(self.first, self.last) | ||
|
||
def __repr__(self): | ||
return "Employee('{}', '{}', {})".format(self.first, self.last, self.pay) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
def insert_emp(emp): | ||
pass | ||
|
||
|
||
def get_emps_by_name(lastname): | ||
pass | ||
|
||
|
||
def update_pay(emp, pay): | ||
pass | ||
|
||
|
||
def remove_emp(emp): | ||
pass | ||
|
||
|
||
|
||
|
||
def update_pay(emp, pay): | ||
with conn: | ||
c.execute("""UPDATE employees SET pay = :pay | ||
WHERE first = :first AND last = :last""", | ||
{'first': emp.first, 'last': emp.last, 'pay': pay}) | ||
|
||
|
||
def remove_emp(emp): | ||
with conn: | ||
c.execute("DELETE from employees WHERE first = :first AND last = :last", | ||
{'first': emp.first, 'last': emp.last}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import sqlite3 | ||
from employee import Employee | ||
|
||
conn = sqlite3.connect(':memory:') | ||
|
||
c = conn.cursor() | ||
|
||
c.execute("""CREATE TABLE employees ( | ||
first text, | ||
last text, | ||
pay integer | ||
)""") | ||
|
||
|
||
def insert_emp(emp): | ||
with conn: | ||
c.execute("INSERT INTO employees VALUES (:first, :last, :pay)", {'first': emp.first, 'last': emp.last, 'pay': emp.pay}) | ||
|
||
|
||
def get_emps_by_name(lastname): | ||
c.execute("SELECT * FROM employees WHERE last=:last", {'last': lastname}) | ||
return c.fetchall() | ||
|
||
|
||
def update_pay(emp, pay): | ||
with conn: | ||
c.execute("""UPDATE employees SET pay = :pay | ||
WHERE first = :first AND last = :last""", | ||
{'first': emp.first, 'last': emp.last, 'pay': pay}) | ||
|
||
|
||
def remove_emp(emp): | ||
with conn: | ||
c.execute("DELETE from employees WHERE first = :first AND last = :last", | ||
{'first': emp.first, 'last': emp.last}) | ||
|
||
emp_1 = Employee('John', 'Doe', 80000) | ||
emp_2 = Employee('Jane', 'Doe', 90000) | ||
|
||
insert_emp(emp_1) | ||
insert_emp(emp_2) | ||
|
||
emps = get_emps_by_name('Doe') | ||
print(emps) | ||
|
||
update_pay(emp_2, 95000) | ||
remove_emp(emp_1) | ||
|
||
emps = get_emps_by_name('Doe') | ||
print(emps) | ||
|
||
conn.close() |