本文整理汇总了Python中app.db.DBApiModule.connect方法的典型用法代码示例。如果您正苦于以下问题:Python DBApiModule.connect方法的具体用法?Python DBApiModule.connect怎么用?Python DBApiModule.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.db.DBApiModule
的用法示例。
在下文中一共展示了DBApiModule.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addLink
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def addLink(form, userId):
linkId = utils.uuid()
kwargs = {}
kwargs["id"] = linkId
kwargs["user_id"] = userId
if form.has_key("url") :
kwargs["url"]=form["url"]
kwargs["url_hash"] = hashlib.md5(kwargs["url"]).hexdigest()
else:
raise Exception("an url must be added")
if form.has_key("title"):
kwargs["title"]=form["title"]
if form.has_key("description"):
kwargs["description"]=form["description"]
if form.has_key("typeName"):
kwargs["type_name"]=form["typeName"]
kwargs["modified_at"]=utils.timeStamp()
#FIXME use other algorithms to get icon logo
iconUrl = utils.extractHomeUrl(kwargs["url"])+"favicon.ico"
conn = db.connect()
db.insertToTable(conn,
"link",
**kwargs)
MetaData.addIconUrl(linkId, iconUrl)
return kwargs
示例2: getUserByName
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def getUserByName(name):
conn = db.connect()
rows = db.selectFrom(conn, {"user"}, "*", name = name)
if rows == []:
#raise Exception("user not found")
return None
return User(rows)
示例3: searchLinkByUser
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def searchLinkByUser(userId, searchValue):
searchLinks="""
SELECT link.id, link.url, link.title, link.description, link.type_name, link.modified_at, md.value
FROM meta_data AS md
JOIN link ON link.id = md.link_id AND link.id IN
(SELECT l.id FROM link AS l WHERE
l.user_id='%s' AND %s OR %s OR %s OR %s)
"""%(userId,
__buildRegexSearchClause("l.url",searchValue),
__buildRegexSearchClause("l.title",searchValue),
__buildRegexSearchClause("l.description",searchValue),
__buildRegexSearchClause("l.type_name",searchValue))
searchTags="""SELECT id, name FROM tag WHERE %s """%(__buildRegexSearchClause("name", searchValue))
conn = db.connect()
cursor = conn.cursor()
cursor.execute(searchLinks)
links = cursor.fetchall()
cursor.execute(searchTags)
tags = cursor.fetchall()
conn.commit()
cursor.close()
return (tags, links)
示例4: createUser
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def createUser(userForm):
conn = db.connect()
userId = str(uuid.uuid4())
db.insertToTable(conn, "user",
id=userId,
name=userForm["username"],
email=userForm["email"])
return userId
示例5: createPasswordForUser
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def createPasswordForUser(userId, password):
conn = db.connect()
value = hashlib.sha256(password).hexdigest()
salt = hashlib.sha256(value+userId).hexdigest()
db.insertToTable(conn, "pw_hash",
user_id=userId,
value=value,
salt=salt)
return True
示例6: create
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def create(userId, name, public):
conn = db.connect()
if public == "true":
public = "1"
else:
public = "0"
count = db.insertToTable(conn, "link_group", id=str(uuid.uuid4()), user_id=userId, name=name, public=public)
return count
示例7: deleteTags
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def deleteTags(tagIds):
query = "delete from tag where "
for _id in tagIds:
query += " id='%s' or\n"%(_id)
query = query[:-4]
conn = db.connect()
cursor = conn.cursor()
affected = cursor.execute(query)
conn.commit()
cursor.close()
return affected
示例8: deleteGroups
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def deleteGroups(groupIds):
query = "delete from link_group where "
for _id in groupIds:
query += " id='%s' or\n"%(_id)
query = query[:-4]
conn = db.connect()
cursor = conn.cursor()
affected = cursor.execute(query)
conn.commit()
cursor.close()
return affected
示例9: dropLinksbyUser
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def dropLinksbyUser(userId, linkIds):
idsClause = ""
for _id in linkIds:
idsClause += " id='%s' or\n"%(_id)
idsClause = idsClause[:-4]
query = "delete from link where user_id='%s' and \n"%(userId) + idsClause
conn = db.connect()
cursor = conn.cursor()
affected = cursor.execute(query)
conn.commit()
cursor.close()
return affected
示例10: getLinks
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def getLinks(tagId):
query = """SELECT link.id, link.url, link.title, link.description, link.type_name, link.modified_at, md.value
FROM meta_data AS md
JOIN link ON link.id = md.link_id AND link.id IN
(SELECT link_id FROM link_tag_map WHERE tag_id = '%s')"""%(tagId)
conn = db.connect()
cursor = conn.cursor()
cursor.execute(query)
links = cursor.fetchall()
conn.commit()
cursor.close()
return links
示例11: update
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def update(link, linkId):
conn = db.connect()
updateEntry = {}
if link.has_key("url") and link["url"] != None:
updateEntry["url"] = link["url"]
if link.has_key("title") and link["title"] != None:
updateEntry["title"] = link["title"]
if link.has_key("description") and link["description"] != None:
updateEntry["description"] = link["description"]
if link.has_key("typeName") and link["typeName"] != None:
updateEntry["type_name"] = link["typeName"]
updateEntry["modified_at"] = utils.timeStamp()
count = db.updateInTable(conn,
updateEntry,
"link",
id=linkId)
return link
示例12: getLinksByUserId
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def getLinksByUserId(userId):
'''
@param userId: user uuid
returns a set of a presentable link
'''
conn = db.connect()
resultSet = db.selectFrom(conn, {"link", "meta_data"},
"link.id",
"link.url",
"link.title",
"link.description",
"link.type_name",
"link.modified_at",
"meta_data.value",
user_id__IN__link=userId,
link_id__IN__meta_data="id__IN__link",
l_key__IN__meta_data="iconUrl")
return resultSet
示例13: addJSONLinksByUser
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def addJSONLinksByUser(data, userId):
#FIXME: change insertion algorithm for sql queries that inserting data
#as zip, json or ...
#curTime = time.time()
query = {"linksQuery":StringHolder("INSERT INTO link (id, user_id, url, url_hash, title, description, type_name, modified_at) VALUES\n"),
"updateLinkSubQuery":{"id":StringHolder(""),
"title":StringHolder(""),
"description":StringHolder(""),
"type_name":StringHolder(""),
"modified_at":StringHolder("")},
"tagsQuery":StringHolder("INSERT INTO tag (id, user_id, name) VALUES\n"),
"mapsQuery":StringHolder("INSERT INTO link_tag_map (tag_id, link_id) VALUES\n"),
"mdQuery":StringHolder("INSERT INTO meta_data (link_id, l_key, value) VALUES\n")}
tags = []
savedTags = tagQM.getTagNames(userId)
savedLinks = linkQM.getLinkUrlsAndIds(userId)
parseData(userId, data, tags, query, savedLinks, savedTags)
#print "calculating time: " + str(utils.timeDifference(curTime)) + " ms"
#curTime = time.time()
conn = db.connect()
cursor = conn.cursor()
if not query["linksQuery"].value.endswith("VALUES\n"):
cursor.execute(query["linksQuery"].value[:-2])
if not query["mdQuery"].value.endswith("VALUES\n"):
cursor.execute(query["mdQuery"].value[:-2])
if not query["tagsQuery"].value.endswith("VALUES\n"):
cursor.execute(query["tagsQuery"].value[:-2])
#FIXME : check if link refer to another tag
if not query["mapsQuery"].value.endswith("VALUES\n"):
cursor.execute(query["mapsQuery"].value[:-2])
if query["updateLinkSubQuery"]["id"].value != "":
cursor.execute(buildUpdateQuery(query["updateLinkSubQuery"]))
conn.commit()
cursor.close()
#print "database request time: " + str(utils.timeDifference(curTime)) + " ms"
return
示例14: create
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def create(userId, name):
conn = db.connect()
count = db.insertToTable(conn, "tag", id=str(uuid.uuid4()), name=name, user_id=userId)
return count
示例15: getTagNames
# 需要导入模块: from app.db import DBApiModule [as 别名]
# 或者: from app.db.DBApiModule import connect [as 别名]
def getTagNames(userId):
conn = db.connect()
resultSet = db.selectFrom(conn, {"tag"}, "name", user_id=userId)
return resultSet