Python sqlalchemy 模块,NVARCHAR 实例源码
我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用sqlalchemy.NVARCHAR。
def create_table(self, name, *columns, **kw):
"""Issue a "create table" instruction using the current migration context.
This directive receives an argument list similar to that of the
Traditional :class:`sqlalchemy.schema.Table` construct,but without the
Metadata::
from sqlalchemy import INTEGER,VARCHAR,NVARCHAR,Column
from alembic import op
op.create_table(
'account',
Column('id',INTEGER,primary_key=True),
Column('name',VARCHAR(50),nullable=False),
Column('description',NVARCHAR(200))
Column('timestamp',TIMESTAMP,server_default=func.Now())
)
Note that :meth:`.create_table` accepts :class:`~sqlalchemy.schema.Column`
constructs directly from the sqlAlchemy library. In particular,
default values to be created on the database side are
specified using the ``server_default`` parameter,and not
``default`` which only specifies Python-side defaults::
from alembic import op
from sqlalchemy import Column,func
# specify "DEFAULT Now" along with the "timestamp" column
op.create_table('account',
Column('timestamp',server_default=func.Now())
)
:param name: Name of the table
:param \*columns: collection of :class:`~sqlalchemy.schema.Column`
objects within
the table,as well as optional :class:`~sqlalchemy.schema.Constraint`
objects
and :class:`~.sqlalchemy.schema.Index` objects.
:param schema: Optional schema name to operate within.
:param \**kw: Other keyword arguments are passed to the underlying
:class:`sqlalchemy.schema.Table` object created for the command.
"""
self.impl.create_table(
self._table(name, **kw)
)