当前位置: 首页>>代码示例>>Python>>正文


Python Session.commit方法代码示例

本文整理汇总了Python中model.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Session的用法示例。


在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LogHandlerTests

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
class LogHandlerTests(reader.LogHandler):
    def __init__(self):
        self.session = Session()
        self.tests = {(item.test, item.subtest) for item in self.session.query(Test)}
        self.new_tests = []

    def _insert_test(self, test, subtest):
        if (test, subtest) not in self.tests:
            test_obj = {"test": test,
                        "subtest": subtest}
            self.new_tests.append(test_obj)
            self.tests.add((test, subtest))

    def test_status(self, data):
        test = self._insert_test(data["test"], data["subtest"])

    def test_end(self, data):
        self._insert_test(data["test"], None)
        sys.stdout.write("-")
        sys.stdout.flush()

    def suite_end(self, data):
        self.session.bulk_insert_mappings(Test, self.new_tests)
        self.session.commit()
        sys.stdout.write(" committing\n")
开发者ID:jgraham,项目名称:wptreport,代码行数:27,代码来源:dbhandler.py

示例2: initialize_device

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def initialize_device():
    """
    Set up the Device info into the database.
    By this time, the HardwareDefinition and SoftwareDefinition
    entries must be entered.
    """
    session = Session()

    hd = session.query(HardwareDefinition).one()
    sd = session.query(SoftwareDefinition).one()

    device = Device(id=hd.serial_number,
                    interior_sensor=hd.interior_sensor,
                    exterior_sensor=hd.exterior_sensor)

    device.hardware_version = hd.hardware_version
    device.software_version = sd.software_version
    device.database_service = True  # database always set to True
    device.device_service = sd.device_service
    device.grainbin_service = sd.grainbin_service
    session.add(device)

    # set grainbin info
    if sd.grainbin_service:
        grainbins = initialize_grainbin(device.id, hd.grainbin_reader_count)
        device.grainbin_count = len(grainbins)
        session.add_all(grainbins)

    session.commit()
    session.close()
    return
开发者ID:nstoik,项目名称:farm_device,代码行数:33,代码来源:db_manage.py

示例3: make_account

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def make_account(username, password):
    session = Session()
    a = Account(username, password)
    session.add(a)
    bot = MBotData("testerbot", 0, 0, )
    
    session.commit()
开发者ID:shmup,项目名称:another-python-mud,代码行数:9,代码来源:account.py

示例4: new_meal_save

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def new_meal_save():
	status, msg = True, ''

	b_name = request.args.get('name')

	s = Session()
	b = Meal(b_name)

	for key, val in request.args.items():
		if key == 'name':
			continue
		a = s.query(Product).filter_by(id=key).first()
		b.products.append(a)

	s.add(b)

	try:
		s.commit()
	except IntegrityError:
		status = False
		msg = 'The meal with name %s already exists' % b_name

	s.close()

	return json.dumps({'ok': status, 'msg': msg})
开发者ID:Azurin,项目名称:kk,代码行数:27,代码来源:controller.py

示例5: create_default_user

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def create_default_user():
    session = Session()
    default_user = User('admin', 'password1234', '[email protected]')
    session.add(default_user)
    session.commit()
    session.close()
    return
开发者ID:nstoik,项目名称:farm_monitor,代码行数:9,代码来源:db_manage.py

示例6: book_save

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def book_save(_id):
	status, msg = True, ''
	b_name = request.args.get('name')

	s = Session()
	b = s.query(Book).filter_by(id=_id).first()

	del b.authors[:]

	for key, val in request.args.items():
		if key == 'name':
			continue
		a = s.query(Author).filter_by(id=key).first()
		b.authors.append(a)

	b.name = b_name
	try:
		s.commit()
	except IntegrityError:
		status = False
		msg = 'The book with name %s already exists' % b_name

	s.close()

	return json.dumps({'ok': status, 'msg': msg})
开发者ID:Azurin,项目名称:beta,代码行数:27,代码来源:controller.py

示例7: clean_run

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def clean_run(name):
    session = Session()
    run = session.query(Run).filter(Run.name==name).first()
    if run is None:
        return
    session.query(Result).filter(Result.run==run).delete(synchronize_session=False)
    session.commit()
开发者ID:jgraham,项目名称:wptreport,代码行数:9,代码来源:dbhandler.py

示例8: create_statuses

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def create_statuses():
    session = Session()
    existing = set(item.name for item in session.query(Status))
    for status in ["PASS", "FAIL", "OK", "ERROR", "TIMEOUT", "CRASH",
                   "ASSERT", "SKIP", "NOTRUN"]:
        if status not in existing:
            session.add(Status(name=status))
    session.commit()
开发者ID:jgraham,项目名称:wptreport,代码行数:10,代码来源:dbhandler.py

示例9: add_order

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
 def add_order(self):
     s = Session()
     ord = Order()
     ord.manager_id = self.parent.user.id
     ord.device =  unicode(self.ui.device.text())
     ord.description =  unicode(self.ui.description)
     ord.client_id = s.query(Client).filter_by(id=unicode(self.ui.client.itemText(self.ui.client.currentIndex())).split()[0]).one().id
     s.add(ord)
     s.commit()
     s.close()
     self.close()
开发者ID:frolova,项目名称:sc,代码行数:13,代码来源:AddOrderWidget.py

示例10: remove_book

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def remove_book():
	b_id   = request.args.get('id')

	s = Session()
	b = s.query(Book).filter_by(id=b_id).first()

	s.delete(b)
	s.commit()
	s.close()

	return json.dumps({'ok': True, 'msg': ''})
开发者ID:Azurin,项目名称:beta,代码行数:13,代码来源:controller.py

示例11: dump_map_to_db

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
    def dump_map_to_db(d_map):
        session = Session()
        
        for t in d_map:
            x, y, v = t
            entry = DataMap(x=x, y=y, value=v)
            session.merge(entry)
        session.commit()
    
        

#Base.metadata.create_all(engine)
开发者ID:shmup,项目名称:another-python-mud,代码行数:14,代码来源:data_map.py

示例12: remove_author

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def remove_author():
	a_id   = request.args.get('id')

	s = Session()
	a = s.query(Author).filter_by(id=a_id).first()

	s.delete(a)
	s.commit()

	s.close()

	return json.dumps({'ok': True, 'msg': ''})
开发者ID:Azurin,项目名称:beta,代码行数:14,代码来源:controller.py

示例13: deleteTable

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def deleteTable():
	session = Session()
	session.execute("DELETE FROM zones_competent_authorities;")
	session.execute("DELETE FROM zones_lau_codes;")
	session.execute("DELETE FROM zone_predecessors;")
	session.execute("DELETE FROM zone_pollutants;")
	session.execute("DELETE FROM zone_legal_acts;")
	session.execute("DELETE FROM zone_time_extension_types;")
	session.execute("DELETE FROM authorities;")
	session.execute("DELETE FROM legal_acts;")
	session.execute("DELETE FROM zones;")
	session.execute("DELETE FROM authorities;")
	session.commit()
开发者ID:eENVplus,项目名称:Processing-Services,代码行数:15,代码来源:deleteTable.py

示例14: add_provider

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def add_provider(db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude):

    # if db is enabled, then open a session with the database
    if db_enabled:
        session = Session()

        # create an instance of the Provider type
        provider = Provider(lastname=lastname, firstname=firstname,
                            credentials=credentials, addr1=addr1, addr2=addr2,
                            city=city, zipcode=zipcode,state=state,
                            latitude=latitude, longitude=longitude)


    #To check if the record already exists in database 
    p = select([Provider.firstname]).where(Provider.firstname+Provider.lastname+Provider.credentials
                                           +Provider.addr1+Provider.addr2 == firstname+lastname+credentials+addr1+addr2)

    res = session.execute(p)
    prov_data = res.fetchone()
    session.close()    

    #To check if record exists, then this step will be skipped
    if not(prov_data):
        session = Session()
        # To fetch the Geographical coordinates from Zip_geotable 
        z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode)
        result = session.execute(z)
        geo_data = result.fetchone()

        if geo_data:
            latitude = geo_data.latitude
            longitude= geo_data.longitude
            #print db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude
            
            
            # create an instance of the Provider type
            provider = Provider(lastname=lastname, firstname=firstname,
                                credentials=credentials, addr1=addr1, addr2=addr2,
                                city=city, zipcode=zipcode,state=state,
                                latitude=latitude, longitude=longitude)            
            

            # if db is enabled, then add to the recordset and commit the txn
            session.add(provider)
            session.commit()
            session.close()
                
    return provider
开发者ID:qlikstar,项目名称:Stride,代码行数:50,代码来源:driver.py

示例15: add_zipdata

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import commit [as 别名]
def add_zipdata(db_enabled, zipcode, latitude, longitude):
    
    # if db is enabled, then open a session with the database
    if db_enabled:
        session = Session()

    # create an instance of the Zip_Geo type
    zip_geo= Zip_geo(zipcode=zipcode, latitude=latitude, longitude=longitude)

    # if db is enabled, then add to the recordset and commit the txn
    if db_enabled:
        session.add(zip_geo)
        session.commit()
        session.close()
                  
    return zip_geo
开发者ID:qlikstar,项目名称:Stride,代码行数:18,代码来源:driver.py


注:本文中的model.Session.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。