From f31c288b65281511338c518bdf7fbe78c985af58 Mon Sep 17 00:00:00 2001 From: jakeogh Date: Sat, 27 Jun 2015 08:40:44 +0000 Subject: add MINVALUE support to Sequence() --- lib/sqlalchemy/engine/interfaces.py | 4 ++-- lib/sqlalchemy/sql/compiler.py | 2 ++ lib/sqlalchemy/sql/schema.py | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 73a8b4635..a58144867 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -252,7 +252,7 @@ class Dialect(object): sequence a dictionary of the form - {'name' : str, 'start' :int, 'increment': int} + {'name' : str, 'start' :int, 'increment': int, 'minvalue': int} Additional column attributes may be present. """ @@ -1147,4 +1147,4 @@ class ExceptionContext(object): .. versionadded:: 1.0.3 - """ \ No newline at end of file + """ diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e9c3d0efa..b8cf32dff 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2299,6 +2299,8 @@ class DDLCompiler(Compiled): text += " INCREMENT BY %d" % create.element.increment if create.element.start is not None: text += " START WITH %d" % create.element.start + if create.element.minvalue is not None: + text += " MINVALUE %d" % create.element.minvalue return text def visit_drop_sequence(self, drop): diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index a8989627d..d49bc2e17 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2040,8 +2040,8 @@ class Sequence(DefaultGenerator): is_sequence = True - def __init__(self, name, start=None, increment=None, schema=None, - optional=False, quote=None, metadata=None, + def __init__(self, name, start=None, increment=None, minvalue=None, + schema=None, optional=False, quote=None, metadata=None, quote_schema=None, for_update=False): """Construct a :class:`.Sequence` object. @@ -2057,6 +2057,11 @@ class Sequence(DefaultGenerator): the database as the value of the "INCREMENT BY" clause. If ``None``, the clause is omitted, which on most platforms indicates an increment of 1. + :param minvalue: the minimum value of the sequence. This + value is used when the CREATE SEQUENCE command is emitted to + the database as the value of the "MINVALUE" clause. If ``None``, + the clause is omitted, which on most platforms indicates a + minvalue of 1. :param schema: Optional schema name for the sequence, if located in a schema other than the default. :param optional: boolean value, when ``True``, indicates that this @@ -2101,6 +2106,7 @@ class Sequence(DefaultGenerator): self.name = quoted_name(name, quote) self.start = start self.increment = increment + self.minvalue = minvalue self.optional = optional if metadata is not None and schema is None and metadata.schema: self.schema = schema = metadata.schema -- cgit v1.2.1 From ad7caa69884bddf6f35da2facc516ab08904c71e Mon Sep 17 00:00:00 2001 From: jakeogh Date: Sat, 27 Jun 2015 18:37:09 +0000 Subject: add MAXVALUE support to Sequence() --- lib/sqlalchemy/engine/interfaces.py | 2 +- lib/sqlalchemy/sql/compiler.py | 2 ++ lib/sqlalchemy/sql/schema.py | 13 ++++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index a58144867..1779f6d48 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -252,7 +252,7 @@ class Dialect(object): sequence a dictionary of the form - {'name' : str, 'start' :int, 'increment': int, 'minvalue': int} + {'name' : str, 'start' :int, 'increment': int, 'minvalue': int, 'maxvalue': int} Additional column attributes may be present. """ diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index b8cf32dff..b3fee60ec 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2301,6 +2301,8 @@ class DDLCompiler(Compiled): text += " START WITH %d" % create.element.start if create.element.minvalue is not None: text += " MINVALUE %d" % create.element.minvalue + if create.element.maxvalue is not None: + text += " MAXVALUE %d" % create.element.maxvalue return text def visit_drop_sequence(self, drop): diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index d49bc2e17..ef84d2680 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2041,8 +2041,8 @@ class Sequence(DefaultGenerator): is_sequence = True def __init__(self, name, start=None, increment=None, minvalue=None, - schema=None, optional=False, quote=None, metadata=None, - quote_schema=None, + maxvalue=None, schema=None, optional=False, quote=None, + metadata=None, quote_schema=None, for_update=False): """Construct a :class:`.Sequence` object. @@ -2061,7 +2061,14 @@ class Sequence(DefaultGenerator): value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "MINVALUE" clause. If ``None``, the clause is omitted, which on most platforms indicates a - minvalue of 1. + minvalue of 1 and -2^63-1 for ascending and descending sequences, + respectively. + :param maxvalue: the maximum value of the sequence. This + value is used when the CREATE SEQUENCE command is emitted to + the database as the value of the "MAXVALUE" clause. If ``None``, + the clause is omitted, which on most platforms indicates a + maxvalue of 2^63-1 and -1 for ascending and descending sequences, + respectively. :param schema: Optional schema name for the sequence, if located in a schema other than the default. :param optional: boolean value, when ``True``, indicates that this -- cgit v1.2.1 From 85ebe01349e0b4314d9e25cacc6701d6fed7b87e Mon Sep 17 00:00:00 2001 From: jakeogh Date: Sat, 27 Jun 2015 18:48:46 +0000 Subject: add NO MINVALUE and NO MAXVALUE support to Sequence() --- lib/sqlalchemy/engine/interfaces.py | 3 ++- lib/sqlalchemy/sql/compiler.py | 4 ++++ lib/sqlalchemy/sql/schema.py | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 1779f6d48..9a31f05ae 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -252,7 +252,8 @@ class Dialect(object): sequence a dictionary of the form - {'name' : str, 'start' :int, 'increment': int, 'minvalue': int, 'maxvalue': int} + {'name' : str, 'start' :int, 'increment': int, 'minvalue': int, + 'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool} Additional column attributes may be present. """ diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index b3fee60ec..f7aa02105 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2303,6 +2303,10 @@ class DDLCompiler(Compiled): text += " MINVALUE %d" % create.element.minvalue if create.element.maxvalue is not None: text += " MAXVALUE %d" % create.element.maxvalue + if create.element.nominvalue is not None: + text += " NO MINVALUE" % create.element.nominvalue + if create.element.nomaxvalue is not None: + text += " NO MAXVALUE" % create.element.nomaxvalue return text def visit_drop_sequence(self, drop): diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index ef84d2680..ccec74a35 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2041,8 +2041,8 @@ class Sequence(DefaultGenerator): is_sequence = True def __init__(self, name, start=None, increment=None, minvalue=None, - maxvalue=None, schema=None, optional=False, quote=None, - metadata=None, quote_schema=None, + maxvalue=None, nominvalue=None, nomaxvalue=None, schema=None, + optional=False, quote=None, metadata=None, quote_schema=None, for_update=False): """Construct a :class:`.Sequence` object. -- cgit v1.2.1 From 66b9a71ce7457b618e9040c1c0bbc2dbd1966354 Mon Sep 17 00:00:00 2001 From: jakeogh Date: Sat, 27 Jun 2015 20:49:46 +0000 Subject: add CYCLE support to Sequence() and docstrings for NO MINVALUE and NO MAXVALUE --- lib/sqlalchemy/engine/interfaces.py | 3 ++- lib/sqlalchemy/sql/compiler.py | 6 ++++-- lib/sqlalchemy/sql/schema.py | 29 +++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 9a31f05ae..3bad765df 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -253,7 +253,8 @@ class Dialect(object): sequence a dictionary of the form {'name' : str, 'start' :int, 'increment': int, 'minvalue': int, - 'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool} + 'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool, + 'cycle': bool} Additional column attributes may be present. """ diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index f7aa02105..d2fa1d553 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2304,9 +2304,11 @@ class DDLCompiler(Compiled): if create.element.maxvalue is not None: text += " MAXVALUE %d" % create.element.maxvalue if create.element.nominvalue is not None: - text += " NO MINVALUE" % create.element.nominvalue + text += " NO MINVALUE" if create.element.nomaxvalue is not None: - text += " NO MAXVALUE" % create.element.nomaxvalue + text += " NO MAXVALUE" + if create.element.cycle is not None: + text += " CYCLE" return text def visit_drop_sequence(self, drop): diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index ccec74a35..ecfa57676 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2041,8 +2041,9 @@ class Sequence(DefaultGenerator): is_sequence = True def __init__(self, name, start=None, increment=None, minvalue=None, - maxvalue=None, nominvalue=None, nomaxvalue=None, schema=None, - optional=False, quote=None, metadata=None, quote_schema=None, + maxvalue=None, nominvalue=None, nomaxvalue=None, cycle=None, + schema=None, optional=False, quote=None, metadata=None, + quote_schema=None, for_update=False): """Construct a :class:`.Sequence` object. @@ -2069,6 +2070,26 @@ class Sequence(DefaultGenerator): the clause is omitted, which on most platforms indicates a maxvalue of 2^63-1 and -1 for ascending and descending sequences, respectively. + :param nominvalue: no minimum value of the sequence. This + value is used when the CREATE SEQUENCE command is emitted to + the database as the value of the "NO MINVALUE" clause. If ``None``, + the clause is omitted, which on most platforms indicates a + minvalue of 1 and -2^63-1 for ascending and descending sequences, + respectively. + :param nomaxvalue: no maximum value of the sequence. This + value is used when the CREATE SEQUENCE command is emitted to + the database as the value of the "NO MAXVALUE" clause. If ``None``, + the clause is omitted, which on most platforms indicates a + maxvalue of 2^63-1 and -1 for ascending and descending sequences, + respectively. + :param cycle: allows the sequence to wrap around when the maxvalue + or minvalue has been reached by an ascending or descending sequence + respectively. This value is used when the CREATE SEQUENCE command + is emitted to the database as the "CYCLE" clause. If the limit is + reached, the next number generated will be the minvalue or maxvalue, + respectively. If cycle=False (the default) any calls to nextval + after the sequence has reached its maximum value will return an + error. :param schema: Optional schema name for the sequence, if located in a schema other than the default. :param optional: boolean value, when ``True``, indicates that this @@ -2114,6 +2135,10 @@ class Sequence(DefaultGenerator): self.start = start self.increment = increment self.minvalue = minvalue + self.maxvalue = maxvalue + self.nominvalue = nominvalue + self.nomaxvalue = nomaxvalue + self.cycle = cycle self.optional = optional if metadata is not None and schema is None and metadata.schema: self.schema = schema = metadata.schema -- cgit v1.2.1