Example #1
0
from database.mysql import MySQLDatabase
from settings import db_config
"""
Retrieve the settings from the
'db_config' dictionary to connect to 
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'), db_config.get('user'),
                   db_config.get('pass'), db_config.get('host'))

# Get all te available tables for
# our database and print them out.
tables = db.get_available_tables()
print tables

columns = db.get_columns_for_table('articles')
print columns
Example #2
0
Retrieve the settings from the
`db_config` dictionary to connect to
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'), db_config.get('user'),
                   db_config.get('pass'), db_config.get('host'))

# Get all the available tables for
# our database annd print them out.
tables = db.get_available_tables()
print tables

# Get all the available columns for our
# articles table and print them out
columns = db.get_columns_for_table('people')
print columns

# Get all the records from
# the people table
all_records = db.select('people')
print "All records: %s" % str(all_records)

# Get all of the records from
# the people table but only the
# `id` and `first_name` columns
column_specific_records = db.select('people', ['id', 'first_name'])
print "Column specific records: %s" % str(column_specific_records)

# Select data using the WHERE clause
where_expression_records = db.select('people', ['first_name'],
# coding=utf-8
from database.mysql import MySQLDatabase
from settings import database

if __name__ == "__main__":
    db = MySQLDatabase(database.get('name'), database.get('username'),
                       database.get('password'), database.get('host'))

    # print db.get_available_tables()
    # print
    print db.get_columns_for_table('people')
    print
    print db.get_columns_for_table('profiles')
    print
    print db.get_columns_for_table('orders')
    print

    # # select a tables worth of data
    # results = db.select('people')
    # for row in results:
    #     print row

    # selecting columns with named tuples
    # results = db.select('people', columns=['id', 'first_name'], named_tuples=True)
    # for row in results:
    #     print row.id, row.first_name

    # use CONCAT and SUM to get a persons full name and total spend
    # people = db.select('people',
    #                     columns=["concat(first_name, ' ', second_name) as full_name",
    #                              "SUM(amount) as total_spend"],
from database.mysql import MySQLDatabase
from settings import db_config

"""
Retrieve the settings from the
`db_config` dictionary to connect to
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'),
                   db_config.get('user'),
                   db_config.get('pass'),
                   db_config.get('host'))

# Get all the available columns for our
# profiles table and print them out
columns = db.get_columns_for_table('profiles')
print columns
from database.mysql import MySQLDatabase
from settings import db_config

"""
Retrieve the settings from the
`db_config` dictionary to connect to
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'),
                   db_config.get('user'),
                   db_config.get('pass'),
                   db_config.get('host'))

# Get all the available columns for our
# orders table and print them out
columns = db.get_columns_for_table('orders')
print columns
Example #6
0
from database.mysql import MySQLDatabase
from settings import db_config
"""
Retrieve the settings from the
'db_config' dictionary to connect to 
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'), db_config.get('user'),
                   db_config.get('pass'), db_config.get('host'))

# Get all te available tables for
# our database and print them out.
tables = db.get_available_tables()
print tables

columns = db.get_columns_for_table('profiles')
print columns
Example #7
0
from database.mysql import MySQLDatabase
from settings import db_config
"""
Retrieve the settings from the
`db_config` dictionary to connect to
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'), db_config.get('user'),
                   db_config.get('pass'), db_config.get('host'))

# Get all the available columns for our
# orders table and print them out
columns = db.get_columns_for_table('orders')
print columns
Example #8
0
from database.mysql import MySQLDatabase
from settings import db_config

"""
Retrieve the settings from the
`db_config` dictionary to connect to
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'),
                   db_config.get('user'),
                   db_config.get('pass'),
                   db_config.get('host'))

# Get all the available tables for
# our database and print them out.
tables = db.get_available_tables()
print tables

# Get all the available columns for our
# articles table and print them out
columns = db.get_columns_for_table('articles')
print columns

columns = db.get_columns_for_table('profiles')
print columns

columns = db.get_columns_for_table('orders')
print columns
Example #9
0
	our database so we can instantiate our
	MySQLDatabase object
	"""
	db = MySQLDatabase(db_config.get('db_name'),
					   db_config.get('user'),
					   db_config.get('pass'),
					   db_config.get('host'))

	# Get all the available tables for 
	# our database annd print them out.
	tables = db.get_available_tables()
	print tables

	# Get all the available columns for our 
	# articles table and print them out
	columns = db.get_columns_for_table('people')
	print columns

	# Get all the records from
	# the people table
	results = db.select('people')

	for row in results:
		print row


	# Selecting columns with named tuples
	results = db.select('people', 
						columns=['id', 'first_name'], named_tuples=True)

	for row in results:
# coding=utf-8
from database.mysql import MySQLDatabase
from settings import database

if __name__ == "__main__":
    db = MySQLDatabase(database.get('name'),
                       database.get('username'),
                       database.get('password'),
                       database.get('host'))

    # print db.get_available_tables()
    # print
    print db.get_columns_for_table('people')
    print
    print db.get_columns_for_table('profiles')
    print
    print db.get_columns_for_table('orders')
    print

    # # select a tables worth of data
    # results = db.select('people')
    # for row in results:
    #     print row

    # selecting columns with named tuples
    # results = db.select('people', columns=['id', 'first_name'], named_tuples=True)
    # for row in results:
    #     print row.id, row.first_name

    # use CONCAT and SUM to get a persons full name and total spend
    # people = db.select('people',
from database.mysql import MySQLDatabase
from settings import db_config

"""
Retrieve the settings from the
`db_config` dictionary to connect to
our database so we can instantiate our
MySQLDatabase object
"""
db = MySQLDatabase(db_config.get('db_name'),
                   db_config.get('user'),
                   db_config.get('pass'),
                   db_config.get('host'))

# Get all the available tables for
# our database annd print them out.
tables = db.get_available_tables()
print tables

# Get all the available columns for our
# articles table and print them out
columns = db.get_columns_for_table('articles')
print columns
Example #12
0
from database.mysql import MySQLDatabase

my_db_connection = MySQLDatabase('employees_db',
                                 'root',
                                 'root')


my_tables = my_db_connection.get_available_tables()

my_col = my_db_connection.get_columns_for_table('dept_emp')

kwrgs = {'where': "emp_no-2"}

results = my_db_connection.select('dept_manager', columns=['em', 'first_name'], named_tuples=True, **kwrgs)



print results
print my_tables
print my_col