Hey everyone,
I've been experimenting with type decorations.
I have the following code snippet. Its goal is to provide a type that is
INTEGER for sqlite, and BIGINTEGER for the other DBMSs. This is needed
because, as far as I know, sqlite can enable AUTOINCREMENT only for INTEGER
types.
class BigInteger(sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.types.TypeEngine # Placeholder, there is
`load_dialect_impl`
def load_dialect_impl(self, dialect):
if dialect.name == 'sqlite':
return dialect.type_descriptor(sqlalchemy.Integer)
else:
return dialect.type_descriptor(sqlalchemy.BigInteger)
Then, I have the following schema definition:
_id = sqlalchemy.Column(
BigInteger, primary_key=True, autoincrement=True
)
In case of SQLite, it works and it is an auto-incrementing primary key.
In case of PostgreSQL instead, it doesn't (no serial is added to the table).
What am I missing here?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.