Finished setting up necessary tables. Pulling active user information. Pulling Address book information for each user..Currently filtering out all but userID 1 for testing purposes.
This commit is contained in:
55
main.py
55
main.py
@@ -1,7 +1,12 @@
|
||||
from sqlalchemy import create_engine, Column, Integer
|
||||
from sqlalchemy import create_engine, Column, Integer, String, BOOLEAN
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
UserAddressID = []
|
||||
ActiveUser = []
|
||||
|
||||
|
||||
engine = create_engine('mssql+pymssql://IDV2Ridge:cWZSGWXS9muyYkHN*@10.10.10.50/IDV2Ridge',echo=False)
|
||||
engine.connect()
|
||||
Base = declarative_base()
|
||||
@@ -14,10 +19,48 @@ class UserAddress(Base):
|
||||
AddressId = Column(Integer, primary_key=True)
|
||||
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
class Address(Base) :
|
||||
__tablename__ = 'Address'
|
||||
|
||||
Id = Column(Integer, primary_key=True)
|
||||
ContactName = Column(String)
|
||||
CompanyName = Column(String)
|
||||
Line1 = Column(String)
|
||||
Line2 = Column(String)
|
||||
City = Column(String)
|
||||
State = Column(String)
|
||||
PostalCode = Column(String)
|
||||
Country = Column(String)
|
||||
PhoneNumber = Column(String)
|
||||
EmailAddress = Column(String)
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'User'
|
||||
|
||||
ID = Column(Integer, primary_key=True)
|
||||
FirstName = Column(String)
|
||||
LastName = Column(String)
|
||||
IsDeleted = Column(BOOLEAN)
|
||||
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
results = session.query(UserAddress).filter(UserAddress.UserId==1)
|
||||
# print(results.query)
|
||||
for row in results:
|
||||
print(row.UserId, " | ", row.AddressId)
|
||||
|
||||
# Get list of active users
|
||||
for user in session.query(User).filter(User.ID == 1):
|
||||
ActiveUser.append([user.ID, user.FirstName, user.LastName])
|
||||
|
||||
# loop through each user in the ActiveUser array
|
||||
for each in ActiveUser:
|
||||
# Combine Users First/Last name into single variable
|
||||
UserName = each[1] + ' ' + each[2]
|
||||
print(UserName)
|
||||
# For each username we're filtering the UserAddress table by their userID and adding it to the UserAddressID array.
|
||||
# The UserAddressID array is then looped through and for each AddressID we pull the Address information
|
||||
for ua in session.query(UserAddress).filter(UserAddress.UserId == each[0]):
|
||||
UserAddressID.append(ua.AddressId)
|
||||
for aid in UserAddressID:
|
||||
for cn in session.query(Address).filter(Address.Id==aid):
|
||||
print(cn.ContactName, cn.CompanyName, cn.Line1, cn.Line2)
|
||||
UserAddressID = []
|
||||
|
||||
Reference in New Issue
Block a user