Example #1
0
def proc_func(lock, counter):

    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker

    from sqlalchemy_declarative import Address, Base, Person

    engine = create_engine('sqlite:///sqlalchemy_example.db',
                           connect_args={'timeout': 30})
    Base.metadata.bind = engine

    DBSession = sessionmaker(bind=engine)
    session = DBSession()

    while True:
        lock.acquire()
        counter += 1
        lock.release()

        print '[%s] adding person %d' % (current_process().name, counter)

        # Insert a Person in the person table
        new_person = Person(name='new person %d' % counter)
        session.add(new_person)
        session.commit()

        # Insert an Address in the address table
        new_address = Address(post_code='00000 %d' % counter,
                              person=new_person)
        session.add(new_address)
        session.commit()
Example #2
0
def person():
    form = PersonForm(request.form)
    if request.method == 'POST' and form.validate():
        print form.name.data
        new_person = Person(name=form.name.data)
        session.add(new_person)
        session.commit()
        print 'hahahah'
        flash('add successful')
        return redirect('/')
    #return redirect('http://www.baidu.com')
    return render_template('person.html', form=form, name='aaaa')
Example #3
0
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_declarative import Person, Address, Base

engine = create_engine('sqlite:///sqlalchemy_example.db')
Base.metadata.bind = engine

Session = sessionmaker(bind=engine)
session = Session()

new_person = Person(name='new_person')
session.add(new_person)
session.commit()

new_address = Address(post_code='00000',
                      person=new_person,
                      street_name='Wall Street')
session.add(new_address)
session.commit()
Example #4
0
)
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from sqlalchemy_declarative import Address, Base, Person

engine = create_engine('sqlite:///sqlalchemy_example.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Insert a Person in the person table
new_person = Person(name='Erik IsAKooKooHead')
session.add(new_person)
session.commit()

# Insert an Address in the address table
new_address = Address(post_code='92117', person=new_person)
session.add(new_address)
session.commit()
engine = create_engine('sqlite:///sqlalchemy_example.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Insert a Person in the person table
new_person = Person(name='Matt')

session.add(new_person)

session.add_all(
    [Person(name='Bev'),
     Person(name='Ben'),
     Person(name='Martha')])

session.commit()

# Insert an Address in the address table
new_address = Address(post_code='00000', person=new_person)
session.add(new_address)
session.commit()
Example #6
0
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Insert a Person in the person table
new_person = Person(name='new person')
new_person.padrao = '-A'
print new_person.name
print new_person.padrao
session.add(new_person)
session.commit()

# Insert an Address in the address table
new_address = Address(post_code='00011', person=new_person)
session.add(new_address)
session.commit()

nova_pessoa = session.query(Address).filter(Address.post_code == '00015').all()
print ''
print ''
print ''
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine
 
DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()
 
# Insert a Person in the person table
new_person = Person(name='new person')
new_person.padrao = '-A'
print new_person.name
print new_person.padrao
session.add(new_person)
session.commit()
 
# Insert an Address in the address table
new_address = Address(post_code='00011', person=new_person)
session.add(new_address)
session.commit()

nova_pessoa = session.query(Address).filter(Address.post_code == '00015').all()
print ''
print ''
print ''