Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find a list of the Flask SQLAlchemy Column types and options?

I hope the word "Types" is used correctly here. Perhaps I mean "Arguments". Feel free to edit.

I am creating a database using Models with Flask with SQLAlchemy, where can I find a list of all the different possible Column arguments such as:

account_id = db.Column(db.Integer, nullable=False)

I know some of the obvious types such as db.Integer or db.String. However I can't seem to find in the SQL Alchemy documentation, or the Flask documentation, a list of all possible arguments for creating a db.Column instance. Am I looking wrong?

Is there a way of differentiating things like db.Integer into tinyint, bigint, etc.?

As for options, such as the nullable=False, I have had trouble finding a good list of all the possible options when creating a db.Column instance.

like image 631
k4kuz0 Avatar asked May 09 '15 08:05

k4kuz0


People also ask

What is column in SQLAlchemy?

function sqlalchemy.orm. column_property(*columns, **kwargs) Provide a column-level property for use with a mapping. Column-based properties can normally be applied to the mapper's properties dictionary using the Column element directly.

How do I query data in a SQLAlchemy Flask?

Querying Records For this purpose Flask-SQLAlchemy provides a query attribute on your Model class. When you access it you will get back a new query object over all records. You can then use methods like filter() to filter the records before you fire the select with all() or first() .

What is Backref in SQLAlchemy?

In Flask-SQLAlchemy, the backref parameter in relationship method allows you to declare a new property under a specified class as seen in the example in their docs: class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) addresses = db.relationship('Address', backref='person ...

What is PickleType?

PickleType. Holds Python objects, which are serialized using pickle. SchemaType. Mark a type as possibly requiring schema-level DDL for usage.


2 Answers

I think you're looking for the Column and Data Types page in the documentation. A little HTML parsing gives:

  • ARRAY
  • BIGINT
  • BINARY
  • BLOB
  • BOOLEAN
  • BigInteger
  • Boolean
  • CHAR
  • CLOB
  • Concatenable
  • DATE
  • DATETIME
  • DECIMAL
  • Date
  • DateTime
  • Enum
  • FLOAT
  • Float
  • INT
  • INTEGER
  • Integer
  • Interval
  • LargeBinary
  • MatchType
  • NCHAR
  • NVARCHAR
  • Numeric
  • PickleType
  • REAL
  • SMALLINT
  • SchemaType
  • SmallInteger
  • String
  • TEXT
  • TIME
  • TIMESTAMP
  • Text
  • Time
  • TypeDecorator
  • TypeEnginBases
  • TypeEngine
  • Unicode
  • VARBINARY
  • VARCHAR
like image 88
Adam Matan Avatar answered Oct 09 '22 13:10

Adam Matan


Documentation is directly perceived through the senses, but if you still wanna see it in commandline, try some IDE, or just type this: (normally our db is just SQLALCHEMY())

>>> print dir(sqlalchemy.types)
["ARRAY","BIGINT","BINARY","BLOB","BOOLEAN","BigInteger","Binary","Boolean","CHAR","CLOB","Concatenable","DATE","DATETIME","DECIMAL","Date","DateTime","Enum","FLOAT","Float","INT","INTEGER","Indexable","Integer","Interval","JSON","LargeBinary","MatchType","NCHAR","NULLTYPE","NUMERIC","NVARCHAR","NullType","Numeric","PickleType","REAL","SMALLINT","STRINGTYPE","SchemaType","SmallInteger","String","TEXT","TIME","TIMESTAMP","Text","Time","TypeDecorator","TypeEngine","Unicode","UnicodeText","UserDefinedType","VARBINARY","VARCHAR","Variant"]
like image 30
Sinux Avatar answered Oct 09 '22 13:10

Sinux