コード例 #1
0
ファイル: 60_class.py プロジェクト: aminzai/mosql
 def fetch(cls, person_id):
     with cls.db as cur:
         cur.execute(cls.select(where={'person_id': person_id}))
         if cur.rowcount:
             person = cls(one_to_dict(cur))
         else:
             person = None
     return person
コード例 #2
0
 def fetch(cls, person_id):
     with cls.db as cur:
         cur.execute(cls.select(where={'person_id': person_id}))
         if cur.rowcount:
             person = cls(one_to_dict(cur))
         else:
             person = None
     return person
コード例 #3
0
def get_user():
    """Retreives a single user from a Database, and render it using a HTML template"""
    try:
        data = json.loads(request.data)
    except ValueError:
        return '', 400
    else:
        email = data['customer']['email']

    # For more complex queries, consider moving queries to a separate module
    with db as cur:
        cur.execute(select('auth_user', {'email': email}, select=('username')))
        try:
            user = one_to_dict(cur)
        except TypeError:
            return '', 404

    template = app.jinja_env.get_template('api/helpscout.html')
    return jsonify({'html': template.render(user)})
コード例 #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2
from mosql.util import star
from mosql.query import insert
from mosql.db import Database, one_to_dict

# We breed another insert with partial arguments.
person_insert = insert.breed({'table': 'person'})

dave = {
    'person_id': 'dave',
    'name': 'Dave',
}

db = Database(psycopg2, host='127.0.0.1')

with db as cur:

    cur.execute(person_insert(set=dave, returning=star))
    print one_to_dict(cur)
    print

    assert 0, 'Rollback!'
コード例 #5
0
ファイル: 30_breed.py プロジェクト: taipeipy/mosql
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2
from mosql.util import star
from mosql.query import insert
from mosql.db import Database, one_to_dict

# We breed another insert with partial arguments.
person_insert = insert.breed({"table": "person"})

dave = {"person_id": "dave", "name": "Dave"}

db = Database(psycopg2, host="127.0.0.1")

with db as cur:

    cur.execute(person_insert(set=dave, returning=star))
    print one_to_dict(cur)
    print

    assert 0, "Rollback!"