本文整理汇总了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))
示例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
示例3: connect_db
def connect_db():
import transwarp.db as dbutil
dbutil.create_engine('sonic513', 'sonic513', 'co2_monitor', port=3306)
示例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__':
示例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')
示例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
示例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()
示例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
示例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
#删除
示例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()
示例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
示例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
示例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
示例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()
示例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