From fcd5d380aeb39dabffb022575c728cc4a66e2355 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 2 Apr 2013 20:24:34 +0300 Subject: [PATCH] Added docs for ScalarList --- docs/index.rst | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 65f1d3c..3ad44ba 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,13 +8,55 @@ SQLAlchemy-Utils SQLAlchemy-Utils provides various utility classes and functions for SQLAlchemy. +ScalarList +---------- + +ScalarList type provides convenient way for saving multiple scalar values in one +column. ScalarList works like list on python side and saves the result as comma-separated list +in the database (custom separators can also be used). + +Example :: + + + from sqlalchemy_utils import ScalarList + + + class User(Base): + __tablename__ = 'user' + id = db.Column(db.Integer, autoincrement=True) + hobbies = db.Column(ScalarList()) + + + user = User() + user.hobbies = [u'football', u'ice_hockey'] + session.commit() + + +You can easily set up integer lists too: + +:: + + + from sqlalchemy_utils import ScalarList + + + class Player(Base): + __tablename__ = 'player' + id = db.Column(db.Integer, autoincrement=True) + points = db.Column(ScalarList(int)) + + + player = Player() + player.points = [11, 12, 8, 80] + session.commit() + API Documentation ----------------- .. module:: sqlalchemy_utils -.. autoclass:: SmartList +.. autoclass:: InstrumentedList :members: .. autofunction:: sort_query .. autofunction:: escape_like