本文整理汇总了Python中db.Database.create_table方法的典型用法代码示例。如果您正苦于以下问题:Python Database.create_table方法的具体用法?Python Database.create_table怎么用?Python Database.create_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.create_table方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_db
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import create_table [as 别名]
def init_db(): # Creates the DB object and sets up hierarchy
if not os.path.exists('data'): # All data should be placed here
os.makedirs('data/files')
db = Database('bot')
db.create_table("plugins", {"plugin_id": "INT PRIMARY KEY NOT NULL", "plugin_name": "TEXT",
"pretty_name": "TEXT", "description": "TEXT", "usage": "TEXT"}, drop_existing=True)
db.create_table("flagged_messages", {"plugin_id": "INT", "message_id": "INT", "chat_id": "INT",
"user_id": "INT", "single_use": "BOOLEAN", "currently_active": "BOOLEAN",
"plugin_data": "TEXT"})
db.create_table("flagged_time", {"plugin_id": "INT", "time": "INT", "plugin_data": "TEXT"})
db.create_table("downloads", {"file_id": "TEXT", "file_path": "TEXT"})
db.create_table("callback_queries", {"plugin_id": "INT", "data": "TEXT", "plugin_data": "TEXT"})
return db
示例2: DbTest
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import create_table [as 别名]
class DbTest(object):
def __init__(self):
self.photostore = Database(True)
def test_tables(self):
# No local index, only hash and range indices
keys = [{'hash': 'hashkey'}, {'range': 'rangekey'}]
self.photostore.create_table('photostore', keys)
data = {
'hashkey' : 'gopa',
'rangekey' : 'sanjose',
'comments' : 'testing again...!'
}
datakeys = {'hashkey' : 'gopa', 'rangekey' : 'sanjose'}
# Store the data
self.photostore.put_data('photostore', data, datakeys)
# Retrieve it
item = self.photostore.get_data('photostore', datakeys)
if item:
print 'GET: photo %s, tag %s, comments %s\n' % \
(item['hashkey'], item['rangekey'], item['comments'])
else:
print 'Item not found\n'
def test_tables_localindex(self):
# Only hash index and one local range index. Local hash has to be the
# same as the hash index because thats how local indices work
keys = [{'hash': 'hashkey'}, {'range': 'rangekey'},
{'hash': 'hashkey', 'local': 'mylocal', 'range': 'rangekey_1'}]
self.photostore.create_table('photostore-local', keys)
# data set 1
data = {
'hashkey' : 'gopa-local',
'rangekey' : 'sanjose-ca-95134',
'rangekey_1' : 'test1',
'comments' : 'testing local this time'
}
datakeys = {'hashkey' : 'gopa-local', 'rangekey' : 'sanjose-ca-95134'}
# store data set 1
self.photostore.put_data('photostore-local', data, datakeys)
# data set 2 .. note that the rangekey_1 which is the local index, is
# the same as in data set 1 .. So when we query with the local index
# (secondary index) we should get both the results
data = {
'hashkey' : 'gopa-local',
'rangekey' : 'sanjose-ca-95134-1',
'rangekey_1' : 'test1',
'comments' : 'testing local this time, duplicate !!'
}
datakeys = {'hashkey' : 'gopa-local',
'rangekey' : 'sanjose-ca-95134-1'}
# store data set 2
self.photostore.put_data('photostore-local', data, datakeys)
# query with the local secondary index
datakeys_query = {'hashkey__eq' : 'gopa-local',
'rangekey_1__eq' : 'test1'}
# we expect to see two entries
item = self.photostore.query_data('photostore-local',
datakeys_query, 'mylocal')
for i in item:
print 'QUERY: [%s, %s, %s, %s]\n' % \
(i['hashkey'], i['rangekey'], i['rangekey_1'],
i['comments'])
# now get item again with the primary hash/range keys
datakeys = {'hashkey' : 'gopa-local', 'rangekey' : 'sanjose-ca-95134'}
item = self.photostore.get_data('photostore-local', datakeys)
if item:
print 'GET: [%s, %s, %s, %s]\n' % \
(item['hashkey'], item['rangekey'], item['rangekey_1'],
item['comments'])
# now get the second with the primary hash/range keys
datakeys = {'hashkey' : 'gopa-local', 'rangekey' : 'sanjose-ca-95134-1'}
item = self.photostore.get_data('photostore-local', datakeys)
if item:
print 'GET: [%s, %s, %s, %s]\n' % \
(item['hashkey'], item['rangekey'], item['rangekey_1'],
item['comments'])
示例3: Excel
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import create_table [as 别名]
# -*- coding: utf-8 -*-
# authors 13077/13130
# data: 05 de outubro de 2014
#
from excel import Excel
from db import Database
# x = Excel("../Data/IPC_Portugal_1977_2013.xls")
x = Excel("C:/Users/Diogo/Dropbox/ESTIG/2/S1/LP/LP-1415/IPC_Portugal_1977_2013.xls")
#x.readFile()
#lista = x.lista
x.read_data()
lista2 = x.lista2
d = Database(lista2)
d.drop_table()
d.create_table()
d.insert_data()
d.test()
# test test tes tes testest se es test es te te s