Exemplo n.º 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'))

# Select a person from the people table
person = db.select('people', named_tuples=True, where="id=2")[0]
print person

# Select all orders for that person
orders = db.select('orders',
                   named_tuples=True,
                   where="person_id=%s" % person.id)
print orders

# Iterate over each order
for order in orders:
    print order
    # Update the amount of each order
    db.update('orders', where="id=%s" % order.id, amount="20.02")
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'))

# Retrieve the first_name column and get the average
# amount spent where the person.id = 1
people = db.select('people', columns=["first_name", "AVG(amount)"
                                      " AS average_spent"],
                   named_tuples=True, where="people.id=1",
                   join="orders ON people.id=orders.person_id")

# Print the results in a format that
# looks like - "<first_name> spends <average_amount>"
for person in people:
    print person.first_name, "spends", person.average_spent
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
from settings import db_config

mysql_db = {
    'host': 'localhost',
    'user': db_config.get('interets_parlementaires', 'user'),
    'passwd': db_config.get('interets_parlementaires', 'passwd'),
    'db': db_config.get('interets_parlementaires', 'db'),
    'port': 3306,
    'use_unicode': True,
    'charset': 'utf8',
}
Exemplo n.º 4
0
# -*- coding: utf-8 -*-

from settings import db_config

mysql_db = {
    'db': db_config.get('nosdeputes', 'db'),
    'kwargs': {
        'host': 'localhost',
        'user': db_config.get('nosdeputes', 'user'),
        'passwd': db_config.get('nosdeputes', 'passwd'),
        'port': 3306,
        'use_unicode': True,
        'charset': 'utf8',
    }
}
Exemplo n.º 5
0
# -*- coding: utf-8 -*-

from settings import db_config

mysql_db = {
    'db': db_config.get('nossenateurs', 'db'),
    'kwargs': {
        'host': 'localhost',
        'user': db_config.get('nossenateurs', 'user'),
        'passwd': db_config.get('nossenateurs', 'passwd'),
        'port': 3306,
        'use_unicode': True,
        'charset': 'utf8',
    }
}