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
if __name__ == "__main__":
	"""
	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
	results = db.select('people')

	for row in results:
		print row

Example #3
0
import MySQLdb as _mysql
# To connect to we need to import the module and use it to create a connection instance

from database.mysql import MySQLDatabase

employees02_db = MySQLDatabase('employees02_db', 'root', '123root', 'localhost')

my_tables = employees02_db.get_available_tables()

print my_tables

my_select = employees02_db.select('employees')

print my_select

kwargs = {'where': "gender=M",
          'order_by': 'emp_no'}

results = employees02_db.select('employees', columns=["concat('first_name', '' , 'last_name') as full_name"],
                                named_tuples=True, **kwargs)

print kwargs


'''
db = _mysql.connect(db='employees02_db',
                    host='localhost',
                    user='******',
                    passwd='123root')

Example #4
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