~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/sql/schema.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1241
1241
                for f in self.foreign_keys]
1242
1242
        if name is None and self.name is None:
1243
1243
            raise exc.InvalidRequestError("Cannot initialize a sub-selectable"
1244
 
                    " with this Column object until it's 'name' has "
 
1244
                    " with this Column object until its 'name' has "
1245
1245
                    "been assigned.")
1246
1246
        try:
1247
1247
            c = self._constructor(
1836
1836
    def _maybe_wrap_callable(self, fn):
1837
1837
        """Wrap callables that don't accept a context.
1838
1838
 
1839
 
        This is to allow easy compatiblity with default callables
 
1839
        This is to allow easy compatibility with default callables
1840
1840
        that aren't specific to accepting of a context.
1841
1841
 
1842
1842
        """
2652
2652
 
2653
2653
        for c in self.columns:
2654
2654
            c.primary_key = True
 
2655
            c.nullable = False
2655
2656
        self.columns.extend(table_pks)
2656
2657
 
2657
2658
    def _reload(self, columns):
2724
2725
 
2725
2726
        Index("some_index", sometable.c.name, sometable.c.address)
2726
2727
 
2727
 
    Functional indexes are supported as well, keeping in mind that at least
2728
 
    one :class:`.Column` must be present::
 
2728
    Functional indexes are supported as well, typically by using the
 
2729
    :data:`.func` construct in conjunction with table-bound
 
2730
    :class:`.Column` objects::
2729
2731
 
2730
2732
        Index("some_index", func.lower(sometable.c.name))
2731
2733
 
2732
2734
    .. versionadded:: 0.8 support for functional and expression-based indexes.
2733
2735
 
 
2736
    An :class:`.Index` can also be manually associated with a :class:`.Table`,
 
2737
    either through inline declaration or using :meth:`.Table.append_constraint`.
 
2738
    When this approach is used, the names of the indexed columns can be specified
 
2739
    as strings::
 
2740
 
 
2741
        Table("sometable", metadata,
 
2742
                        Column("name", String(50)),
 
2743
                        Column("address", String(100)),
 
2744
                        Index("some_index", "name", "address")
 
2745
                )
 
2746
 
 
2747
    To support functional or expression-based indexes in this form, the
 
2748
    :func:`.text` construct may be used::
 
2749
 
 
2750
        from sqlalchemy import text
 
2751
 
 
2752
        Table("sometable", metadata,
 
2753
                        Column("name", String(50)),
 
2754
                        Column("address", String(100)),
 
2755
                        Index("some_index", text("lower(name)"))
 
2756
                )
 
2757
 
 
2758
    .. versionadded:: 0.9.5 the :func:`.text` construct may be used to
 
2759
       specify :class:`.Index` expressions, provided the :class:`.Index`
 
2760
       is explicitly associated with the :class:`.Table`.
 
2761
 
 
2762
 
2734
2763
    .. seealso::
2735
2764
 
2736
2765
        :ref:`schema_indexes` - General information on :class:`.Index`.
2757
2786
        :param \*expressions:
2758
2787
          Column expressions to include in the index.   The expressions
2759
2788
          are normally instances of :class:`.Column`, but may also
2760
 
          be arbitrary SQL expressions which ultmately refer to a
 
2789
          be arbitrary SQL expressions which ultimately refer to a
2761
2790
          :class:`.Column`.
2762
2791
 
2763
2792
        :param unique=False:
2785
2814
                visitors.traverse(expr, {}, {'column': cols.append})
2786
2815
                if cols:
2787
2816
                    columns.append(cols[0])
2788
 
                else:
2789
 
                    columns.append(expr)
2790
2817
 
2791
2818
        self.expressions = expressions
2792
2819
        self.name = quoted_name(name, kw.pop("quote", None))
2798
2825
        ColumnCollectionMixin.__init__(self, *columns)
2799
2826
 
2800
2827
 
2801
 
 
2802
2828
    def _set_parent(self, table):
2803
2829
        ColumnCollectionMixin._set_parent(self, table)
2804
2830
 
2823
2849
        self.expressions = [
2824
2850
            expr if isinstance(expr, ClauseElement)
2825
2851
            else colexpr
2826
 
            for expr, colexpr in zip(self.expressions, self.columns)
 
2852
            for expr, colexpr in util.zip_longest(self.expressions, self.columns)
2827
2853
        ]
2828
2854
 
2829
2855
    @property
2865
2891
        return 'Index(%s)' % (
2866
2892
                    ", ".join(
2867
2893
                        [repr(self.name)] +
2868
 
                        [repr(c) for c in self.columns] +
 
2894
                        [repr(e) for e in self.expressions] +
2869
2895
                        (self.unique and ["unique=True"] or [])
2870
2896
                    ))
2871
2897
 
2948
2974
          The values associated with each "constraint class" or "constraint
2949
2975
          mnemonic" key are string naming templates, such as
2950
2976
          ``"uq_%(table_name)s_%(column_0_name)s"``,
2951
 
          which decribe how the name should be composed.  The values associated
 
2977
          which describe how the name should be composed.  The values associated
2952
2978
          with user-defined "token" keys should be callables of the form
2953
2979
          ``fn(constraint, table)``, which accepts the constraint/index
2954
2980
          object and :class:`.Table` as arguments, returning a string
3362
3388
                self.__engines[bind] = e
3363
3389
                self.context._engine = e
3364
3390
        else:
3365
 
            # TODO: this is squirrely.  we shouldnt have to hold onto engines
 
3391
            # TODO: this is squirrely.  we shouldn't have to hold onto engines
3366
3392
            # in a case like this
3367
3393
            if bind not in self.__engines:
3368
3394
                self.__engines[bind] = bind