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


Python db.create_engine函数代码示例

本文整理汇总了Python中transwarp.db.create_engine函数的典型用法代码示例。如果您正苦于以下问题:Python create_engine函数的具体用法?Python create_engine怎么用?Python create_engine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: generate_tables

def generate_tables():
    if not db.engine:
        db.create_engine('awesome.db')
    
    sql = lambda x:''.join(x().__sql__.split('\n')[1:])   
    db.update(sql(User))
    db.update(sql(Blog))
    db.update(sql(Comment))
开发者ID:Charles-Lau-,项目名称:awesome_python_app,代码行数:8,代码来源:models.py

示例2: User

#!/usr/bin/env python
# -*- coding:utf-8 -*-

from models import User,Blog,Comment
from transwarp import db

db.create_engine(user='root',password='qwerty',database='awesome-webapp')
u = User(name='Test',email='[email protected]',password='123456',image='about:blank')
u.insert()
print 'new user id:',u.id

u1 = User.find_first('where email=?','[email protected]')
print 'find user\'s name:',u1.name

u1.delete()

u2 = User.find_first('where email=?', '[email protected]')
print 'find user:', u2
开发者ID:wenhuwang,项目名称:awesome-webapp,代码行数:18,代码来源:test_db.py

示例3: connect_db

def connect_db():
    import transwarp.db as dbutil
    dbutil.create_engine('sonic513', 'sonic513', 'co2_monitor', port=3306)
开发者ID:hazelor,项目名称:COO_new,代码行数:3,代码来源:setting_create_tables.py

示例4: WSGIApplication

'''
A WSGI application entry.
'''

import logging; logging.basicConfig(level=logging.INFO)

import os

from transwarp import db
from transwarp.web import WSGIApplication, Jinja2TemplateEngine

from config import configs

# init db:
db.create_engine(**configs.db)

# init wsgi app:
wsgi = WSGIApplication(os.path.dirname(os.path.abspath(__file__)))

template_engine = Jinja2TemplateEngine(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'))

wsgi.template_engine = template_engine

import urls

wsgi.add_interceptor(urls.user_interceptor)
wsgi.add_interceptor(urls.manage_interceptor)
wsgi.add_module(urls)

if __name__ == '__main__':
开发者ID:Spacebody,项目名称:ProfStudSystem,代码行数:30,代码来源:wsgiapp.py

示例5:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from transwarp import db

db.create_engine(user='root', password='', database='test', host='127.0.0.1', port='3307')
开发者ID:amylovesong,项目名称:python,代码行数:6,代码来源:test_transwarp_db.py

示例6: User

#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Wang Shaohua'

from models import User
from transwarp import db


db.create_engine(user='wshh08', password='2910', database='awesome')


u = User(name='Test', email='[email protected]', password='1234567890', image='about:blank')


u.insert()


print 'new user id:', u.id


u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name


# u1.delete()


u2 = User.find_first('where email=?', '[email protected]')
print 'find user:', u2
开发者ID:wshh08,项目名称:awesome-python-webapp,代码行数:30,代码来源:test_db.py

示例7: delete

        pk = self.__primary_key__.name
        args.append(getattr(self, pk))
        db.update('update `%s` set %s where %s=?' % (self.__table__, ','.join(L), pk), *args)
        return self

    def delete(self):
        self.pre_delete and self.pre_delete()
        pk = self.__primary_key__.name
        args = (getattr(self, pk), )
        db.update('delete from `%s` where `%s`=?' % (self.__table__, pk), *args)
        return self

    def insert(self):
        self.pre_insert and self.pre_insert()
        params = {}
        for k, v in self.__mappings__.iteritems():
            if v.insertable:
                if not hasattr(self, k):
                    setattr(self, k, v.default)
                params[v.name] = getattr(self, k)
        db.insert('%s' % self.__table__, **params)
        return self

if __name__=='__main__':
    logging.basicConfig(level=logging.DEBUG)
    db.create_engine('www-data', 'www-data', 'test')
    db.update('drop table if exists user')
    db.update('create table user (id int primary key, name text, email text, passwd text, last_modified real)')
    import doctest
    doctest.testmod()
开发者ID:ethan8621,项目名称:Alvin,代码行数:30,代码来源:orm.py

示例8: User

from models import User, Blog, Comment
import logging

from transwarp import db

logging.basicConfig(level = logging.DEBUG)

db.create_engine(user = 'root', password = 'password', database = 'myblog')

u = User(name='Test', email='[email protected]', password='1234567890', image='about:blank')

u.insert()

print 'new user id:', u.id
print 'create time:', u.created_at

u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name

u1.delete()

u2 = User.find_by('where email=?', '[email protected]')

print 'find user:', u2
开发者ID:Rain94,项目名称:myblog,代码行数:24,代码来源:teat_model.py

示例9: User

#coding:utf8

from models import User, Blog, Comment
from transwarp import db

#开启数据库引擎,连接数据库
db.create_engine(user='root', password='123456', database='test')

#实例化一个user类,做好形成表格的准备,进行初始化Model类--》ModelMetalClass采集属性字段,然后通过Model类的函数来进行表格数据操作
u = User(name='Test', email='[email protected]', password='123456', image='about:blank', admin=False)

print User().__sql__()

#形成表格之前,判断此表格是否存在,存在下drop
db.update('drop table if exists user')

#形成表格后进行字段栏的构建,手写创建表的sql脚本
#db.update('create table user (id varchar(50) primary key, email text, password text, admin text, name text, image text, create_at float)')
#表比较多话,用Model对象通过脚本直接生成sql脚本
db.update(User().__sql__())

#字段栏形成后,进行数据的插入
u.insert()

print 'new user id:', u.id

#查询
u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name

#删除
开发者ID:SmallPuddingComing,项目名称:mylearn,代码行数:31,代码来源:test_db.py

示例10: isinstance

#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__author__ = 'Jeffwu'

from models import User, Blog, Comment
from transwarp.orm import StringField,Field

from transwarp import db

db.create_engine(user='root', passwd='', database='awesome')

u = User(name='Test', email='[email protected]', passwd='1234567890', image='about:blank')

print isinstance(u.name,StringField)


#u.insert()

#print 'new user id:', u.id

#u1 = User.find_first('where email=?', '[email protected]')
#print 'find user\'s name:', u1.name

#u1.delete()
开发者ID:X010,项目名称:python-awe,代码行数:30,代码来源:test_db.py

示例11: User

'''
Created on Jun 11, 2016

@author: zlp
'''
from models import User, Blog, Comment
from transwarp import db
import logging

db.create_engine(user='root', password='6129544', database='awesome')
u = User(name='Test', email='[email protected]', password='123456', image='about:blank')
# it can only be inserted once, in the DB, Email column is distinct, if insert multiple time, it will return error message.
try:
    u.insert()
except Exception,e:
    logging.warning('It seems that the same user has been inserted, %s' % e)
print 'new user id:', u.id
 
#Here I add to print the cls name
u1 = User.find_first('where email=?', '[email protected]')
print u1
开发者ID:blackboarddd,项目名称:PyTest,代码行数:21,代码来源:test_db.py

示例12: User

# -*- coding: utf-8 -*-

__author__ = 'ghost'

from models import User, Blog, Comment
from transwarp import db

db.create_engine(user='root', passwd='', db='webapp')

u = User(email='[email protected]', passwd='111111', admin=True, nickname='rsj217', avatar='')
print u
u.insert()
# uu = User.find_by("WHERE admin=1")
# print uu[0].passwd
开发者ID:rsj217,项目名称:python-webapp,代码行数:14,代码来源:test_db.py

示例13: User

#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'tiger'


from models import User, Blog, Comment

from transwarp import db

db.create_engine(user='root', password='tiger', database='awesome')

u = User(name='Test', email='[email protected]', password='1234567890', image='about:blank')

u.insert()

print 'new user id:', u.id

u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name

# u1.delete()
#
# u2 = User.find_first('where email=?', '[email protected]')
# print 'find user:', u2
开发者ID:jappre,项目名称:mutation,代码行数:25,代码来源:test_db.py

示例14: test

formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
console.setFormatter(formatter)
# 将定义好的console日志handler添加到root logger
logging.getLogger('').addHandler(console)

from models import User, Blog, Comment

from transwarp import db


@db.with_transaction
def test():
    u = User(name='Test', email='[email protected]', password='1234567890', image='about:blank')

    u.insert()

    print 'new user id:', u.id

    u1 = User.find_first('where email=?', '[email protected]')
    print 'find user\'s name:', u1.name

    u1.delete()

    u2 = User.find_first('where email=?', '[email protected]')
    print 'find user:', u2


if __name__ == '__main__':
    db.create_engine(user='mysql', password='mysql', database='awesome')
    test()
    print time.time() , time.strptime()
开发者ID:jy00464346,项目名称:mytest-python-webapp,代码行数:31,代码来源:test_db.py

示例15: User

#!/usr/bin/env python

from models import User,Blog,Comment

from transwarp import db

import logging

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    db.create_engine(user='edison',password='654321',database='awesome')
    u = User(name='Test',email='[email protected]',passwd='987654321',image='about:blank')
    u.insert()

    print 'new user id:',u.id

    u1 = User.find_first('where email=?','[email protected]')
    print 'find user\'s name:',u1.name

    u1.delete()

    u2 = User.find_first('where email=?','[email protected]')
    print 'find user\'s name:',u2.name
开发者ID:xinedison,项目名称:myweb,代码行数:24,代码来源:test_db.py


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