Python SQLAlchemy MySql Columns

Lets switch to SqlAlchemy to get columns


from sqlalchemy import create_engine, Table
from sqlalchemy.orm import scoped_session,sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import sqlite3

class DBSession1():
    def __init__(self):
        dbhost = "x"
        dbuser = "x"
        dbpass = "x"
        dbdbas = "x"
        self.engine1= create_engine('mysql://' + dbuser + ":" + dbpass + "@" + dbhost + "/" + dbdbas)
        self.Base1 = declarative_base()
        return None

if __name__=="__main__":

    x = DBSession1()
    customers = Table('customer', x.Base1.metadata, autoload=True, autoload_with=x.engine1)
    print customers.columns

Once again, we get a list of columns.You will need to put your MySql database credential in for this to work, often times the host is localhost.

Here is a loop to look at even more information on the database columns. You can tack this onto the end of the code segment above.

    for col in customers.columns:

0 thoughts on “Python SQLAlchemy MySql Columns”

  1. Method backups, whilst dependable, will not be stored within the cloud and ca not be discovered when they leave this phone, so some phones are nevertheless Cautiously prepare the customers for the cloud service feature, which retailers the phone is data inside the cloud, so that in case of accidental deletion of the phone is data The backup information could be retrieved directly in line with the account quantity. This technique also wo not take up a great deal phone memory, so it will not be hard to get back the phone videos you accidentally deleted!

Leave a Reply

Your email address will not be published. Required fields are marked *