本文整理汇总了Python中sqlalchemy.Table方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.Table方法的具体用法?Python sqlalchemy.Table怎么用?Python sqlalchemy.Table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.Table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def upgrade():
op.add_column("resource_type", sa.Column('tablename', sa.String(18),
nullable=True))
resource_type = sa.Table(
'resource_type', sa.MetaData(),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('tablename', sa.String(18), nullable=True)
)
op.execute(resource_type.update().where(
resource_type.c.name == "instance_network_interface"
).values({'tablename': op.inline_literal("'instance_net_int'")}))
op.execute(resource_type.update().where(
resource_type.c.name != "instance_network_interface"
).values({'tablename': resource_type.c.name}))
op.alter_column("resource_type", "tablename", type_=sa.String(18),
nullable=False)
op.create_unique_constraint("uniq_resource_type0tablename",
"resource_type", ["tablename"])
示例2: importyaml
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def importyaml(connection,metadata,sourcePath):
eveGraphics = Table('eveGraphics',metadata)
print "Importing Graphics"
print "opening Yaml"
with open(os.path.join(sourcePath,'fsd','graphicIDs.yaml'),'r') as yamlstream:
print "importing"
trans = connection.begin()
graphics=load(yamlstream,Loader=SafeLoader)
print "Yaml Processed into memory"
for graphic in graphics:
connection.execute(eveGraphics.insert(),
graphicID=graphic,
sofFactionName=graphics[graphic].get('sofFactionName',''),
graphicFile=graphics[graphic].get('graphicFile',''),
sofHullName=graphics[graphic].get('sofHullName',''),
sofRaceName=graphics[graphic].get('sofRaceName',''),
description=graphics[graphic].get('description',''))
trans.commit()
示例3: importyaml
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def importyaml(connection,metadata,sourcePath,language='en'):
invGroups = Table('invGroups',metadata)
trnTranslations = Table('trnTranslations',metadata)
print "Importing Groups"
print "opening Yaml"
with open(os.path.join(sourcePath,'fsd','groupIDs.yaml'),'r') as yamlstream:
trans = connection.begin()
groupids=load(yamlstream,Loader=SafeLoader)
print "Yaml Processed into memory"
for groupid in groupids:
connection.execute(invGroups.insert(),
groupID=groupid,
categoryID=groupids[groupid].get('categoryID',0),
groupName=groupids[groupid].get('name',{}).get(language,'').decode('utf-8'),
iconID=groupids[groupid].get('iconID'),
useBasePrice=groupids[groupid].get('useBasePrice'),
anchored=groupids[groupid].get('anchored',0),
anchorable=groupids[groupid].get('anchorable',0),
fittableNonSingleton=groupids[groupid].get('fittableNonSingleton',0),
published=groupids[groupid].get('published',0))
if (groupids[groupid].has_key('name')):
for lang in groupids[groupid]['name']:
connection.execute(trnTranslations.insert(),tcID=7,keyID=groupid,languageID=lang,text=groupids[groupid]['name'][lang].decode('utf-8'));
trans.commit()
示例4: importyaml
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def importyaml(connection,metadata,sourcePath,language='en'):
print "Importing dogma attribute categories"
dgmAttributeCategories = Table('dgmAttributeCategories',metadata)
print "opening Yaml"
trans = connection.begin()
with open(os.path.join(sourcePath,'fsd','dogmaAttributeCategories.yaml'),'r') as yamlstream:
print "importing"
dogmaAttributeCategories=load(yamlstream,Loader=SafeLoader)
print "Yaml Processed into memory"
for dogmaAttributeCategoryID in dogmaAttributeCategories:
attribute = dogmaAttributeCategories[dogmaAttributeCategoryID]
connection.execute(dgmAttributeCategories.insert(),
categoryID=dogmaAttributeCategoryID,
categoryName=attribute['name'],
categoryDescription=attribute['description']
)
trans.commit()
示例5: importyaml
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def importyaml(connection,metadata,sourcePath):
print "Importing BSD Tables"
files=glob.glob(os.path.join(sourcePath,'bsd','*.yaml'))
for file in files:
head, tail = os.path.split(file)
tablename=tail.split('.')[0]
print tablename
tablevar = Table(tablename,metadata)
print "Importing {}".format(file)
print "Opening Yaml"
trans = connection.begin()
with open(file,'r') as yamlstream:
rows=load(yamlstream,Loader=SafeLoader)
print "Yaml Processed into memory"
for row in rows:
connection.execute(tablevar.insert().values(row))
trans.commit()
示例6: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def upgrade():
op.add_column('keypairs', sa.Column('ssh_public_key', sa.String(length=750), nullable=True))
op.add_column('keypairs', sa.Column('ssh_private_key', sa.String(length=2000), nullable=True))
# partial table to be preserved and referred
metadata = sa.MetaData(naming_convention=convention)
keypairs = sa.Table(
'keypairs', metadata,
sa.Column('access_key', sa.String(length=20), primary_key=True),
sa.Column('ssh_public_key', sa.String(length=750), nullable=True),
sa.Column('ssh_private_key', sa.String(length=2000), nullable=True),
)
# Fill in SSH keypairs in every keypairs.
conn = op.get_bind()
query = sa.select([keypairs.c.access_key]).select_from(keypairs)
rows = conn.execute(query).fetchall()
for row in rows:
pubkey, privkey = generate_ssh_keypair()
query = (sa.update(keypairs)
.values(ssh_public_key=pubkey, ssh_private_key=privkey)
.where(keypairs.c.access_key == row.access_key))
conn.execute(query)
示例7: _show_create_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def _show_create_table(self, connection, table, charset=None,
full_name=None):
"""Run SHOW CREATE TABLE for a ``Table``."""
if full_name is None:
full_name = self.identifier_preparer.format_table(table)
st = "SHOW CREATE TABLE %s" % full_name
rp = None
try:
rp = connection.execution_options(
skip_user_error_events=True).execute(st)
except exc.DBAPIError as e:
if self._extract_error_code(e.orig) == 1146:
raise exc.NoSuchTableError(full_name)
else:
raise
row = self._compat_first(rp, charset=charset)
if not row:
raise exc.NoSuchTableError(full_name)
return row[1].strip()
return sql
示例8: _describe_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def _describe_table(self, connection, table, charset=None,
full_name=None):
"""Run DESCRIBE for a ``Table`` and return processed rows."""
if full_name is None:
full_name = self.identifier_preparer.format_table(table)
st = "DESCRIBE %s" % full_name
rp, rows = None, None
try:
try:
rp = connection.execution_options(
skip_user_error_events=True).execute(st)
except exc.DBAPIError as e:
if self._extract_error_code(e.orig) == 1146:
raise exc.NoSuchTableError(full_name)
else:
raise
rows = self._compat_fetchall(rp, charset=charset)
finally:
if rp:
rp.close()
return rows
示例9: bind
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def bind(self):
"""Return the current "bind".
In online mode, this is an instance of
:class:`sqlalchemy.engine.Connection`, and is suitable
for ad-hoc execution of any kind of usage described
in :ref:`sqlexpression_toplevel` as well as
for usage with the :meth:`sqlalchemy.schema.Table.create`
and :meth:`sqlalchemy.schema.MetaData.create_all` methods
of :class:`~sqlalchemy.schema.Table`,
:class:`~sqlalchemy.schema.MetaData`.
Note that when "standard output" mode is enabled,
this bind will be a "mock" connection handler that cannot
return results and is only appropriate for a very limited
subset of commands.
"""
return self.connection
示例10: schemas
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def schemas(self):
"""
object: An object with attributes corresponding to the names of the schemas
in this database.
"""
from lazy_object_proxy import Proxy
def get_schemas():
if not getattr(self, '_schemas', None):
assert getattr(self, '_sqlalchemy_metadata', None) is not None, (
"`{class_name}` instances do not provide the required sqlalchemy metadata "
"for schema exploration.".format(class_name=self.__class__.__name__)
)
self._schemas = Schemas(self._sqlalchemy_metadata)
return self._schemas
return Proxy(get_schemas)
# Extend Table to support returning pandas description of table
示例11: get_type_of_fields
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def get_type_of_fields(fields, table):
"""
Return data types of `fields` that are in `table`. If a given
parameter is empty return primary key.
:param fields: list - list of fields that need to be returned
:param table: sa.Table - the current table
:return: list - list of the tuples `(field_name, fields_type)`
"""
if not fields:
fields = table.primary_key
actual_fields = [
field for field in table.c.items() if field[0] in fields
]
data_type_fields = {
name: FIELD_TYPES.get(type(field_type.type), rc.TEXT_FIELD.value)
for name, field_type in actual_fields
}
return data_type_fields
示例12: get_type_for_inputs
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def get_type_for_inputs(table):
"""
Return information about table's fields in dictionary type.
:param table: sa.Table - the current table
:return: list - list of the dictionaries
"""
return [
dict(
type=INPUT_TYPES.get(
type(field_type.type), rc.TEXT_INPUT.value
),
name=name,
isPrimaryKey=(name in table.primary_key),
props=None,
) for name, field_type in table.c.items()
]
示例13: generate_config
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def generate_config(entities, base_url, template_name=None,
template_folder=None, desc=None, extra_context=None):
template_name = template_name or 'config.j2'
desc = desc or 'aiohttp_admin'
if all(isinstance(ent[2], sa.Table) for ent in entities):
build_entity = table_entity
else:
build_entity = trafaret_entity
context = {
"admin_description": desc,
"base_url": base_url if base_url.endswith("/") else base_url + '/',
"entities": [build_entity(n, pk, s) for n, pk, s in entities],
"extra_context": extra_context,
}
tf = gather_template_folders(template_folder)
loader = jinja2.FileSystemLoader(tf)
env = jinja2.Environment(loader=loader)
template = env.get_template(template_name)
text = template.render(context)
return text
示例14: sa_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def sa_table():
choices = ['a', 'b', 'c']
meta = sa.MetaData()
post = sa.Table(
'test_post', meta,
sa.Column('id', sa.Integer, nullable=False),
sa.Column('title', sa.String(200), nullable=False),
sa.Column('category', sa.String(200), nullable=True),
sa.Column('body', sa.Text, nullable=False),
sa.Column('views', sa.Integer, nullable=False),
sa.Column('average_note', sa.Float, nullable=False),
# sa.Column('pictures', postgresql.JSON, server_default='{}'),
sa.Column('published_at', sa.DateTime, nullable=False),
# sa.Column('tags', postgresql.ARRAY(sa.Integer), server_default='{}'),
sa.Column('status',
sa.Enum(*choices, name="enum_name", native_enum=False),
server_default="a", nullable=False),
sa.Column('visible', sa.Boolean, nullable=False),
# Indexes #
sa.PrimaryKeyConstraint('id', name='post_id_pkey'))
return post
示例15: _create_table_setup
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Table [as 别名]
def _create_table_setup(self):
from sqlalchemy import Table, Column, PrimaryKeyConstraint
column_names_and_types = \
self._get_column_names_and_types(self._sqlalchemy_type)
columns = [Column(name, typ, index=is_index)
for name, typ, is_index in column_names_and_types]
if self.keys is not None:
if not is_list_like(self.keys):
keys = [self.keys]
else:
keys = self.keys
pkc = PrimaryKeyConstraint(*keys, name=self.name + '_pk')
columns.append(pkc)
schema = self.schema or self.pd_sql.meta.schema
# At this point, attach to new metadata, only attach to self.meta
# once table is created.
from sqlalchemy.schema import MetaData
meta = MetaData(self.pd_sql, schema=schema)
return Table(self.name, meta, *columns, schema=schema)