sqlbuilder 0.7.9.4

SmartSQL - lightweight sql builder.

SmartSQL - lightweight sql builder, follows the KISS principle, less than 50 Kb.

You can use SmartSQL separatelly, or with Django, or with super-lightweight Autumn ORM, or with super-lightweight datamapper Openorm etc.

Home Page: https://bitbucket.org/emacsway/sqlbuilder

LICENSE:

  • License is BSD

Short manual for sqlbuilder.smartsql

table:

In [9]: T.book
Out[9]: <Table: "book", []>

In [10]: T.book__a
Out[10]: <TableAlias: "a", []>

In [11]: T.book.as_('a')
Out[11]: <TableAlias: "a", []>

field:

In [13]: T.book.name
Out[13]: <Field: "book"."name", []>

In [14]: T.book.name.as_('a')
Out[14]: <Alias: "a", []>

In [15]: F.book__name
Out[15]: <Field: "book"."name", []>

In [16]: F.book__name__a
Out[16]: <Alias: "a", []>

In [17]: F.book__name.as_('a')
Out[17]: <Alias: "a", []>

table operator:

In [4]: (T.book & T.author).on(T.book.author_id == T.author.id)
Out[4]: <TableJoin: "book" INNER JOIN "author" ON ("book"."author_id" = "author"."id"), []>

In [5]: (T.book + T.author).on(T.book.author_id == T.author.id)
Out[5]: <TableJoin: "book" LEFT OUTER JOIN "author" ON ("book"."author_id" = "author"."id"), []>

In [6]: (T.book - T.author).on(T.book.author_id == T.author.id)
Out[6]: <TableJoin: "book" RIGHT OUTER JOIN "author" ON ("book"."author_id" = "author"."id"), []>

In [7]: (T.book | T.author).on(T.book.author_id == T.author.id)
Out[7]: <TableJoin: "book" FULL OUTER JOIN "author" ON ("book"."author_id" = "author"."id"), []>

In [8]: (T.book * T.author).on(T.book.author_id == T.author.id)
Out[8]: <TableJoin: "book" CROSS JOIN "author" ON ("book"."author_id" = "author"."id"), []>

condition operator:

In [19]: (T.author.first_name != 'Tom') & (T.author.last_name.in_(('Smith', 'Johnson')))
Out[19]: <Condition: "author"."first_name" <> %s AND "author"."last_name" IN (%s, %s), ['Tom', 'Smith', 'Johnson']>

In [20]: (T.author.first_name != 'Tom') | (T.author.last_name.in_(('Smith', 'Johnson')))
Out[20]: <Condition: "author"."first_name" <> %s OR "author"."last_name" IN (%s, %s), ['Tom', 'Smith', 'Johnson']>

In [21]: T.author.last_name.startswith('Sm')
Out[21]: <Condition: "author"."last_name" LIKE %s || %s, ['Sm', u'%']>

In [22]: T.author.last_name.istartswith('Sm')
Out[22]: <Condition: "author"."last_name" ILIKE %s || %s, ['Sm', u'%']>

In [23]: T.author.last_name.contains('Sm')
Out[23]: <Condition: "author"."last_name" LIKE %s || %s || %s, [u'%', 'Sm', u'%']>

In [24]: T.author.last_name.icontains('Sm')
Out[24]: <Condition: "author"."last_name" ILIKE %s || %s || %s, [u'%', 'Sm', u'%']>

In [25]: T.author.last_name.endswith('Sm')
Out[25]: <Condition: "author"."last_name" LIKE %s || %s, [u'%', 'Sm']>

In [26]: T.author.last_name.iendswith('Sm')
Out[26]: <Condition: "author"."last_name" ILIKE %s || %s, [u'%', 'Sm']>

In [27]: T.author.age.between(20, 30)
Out[27]: <Between: "author"."age" BETWEEN %s AND %s, [20, 30]>

usage eg:

In [31]: QS().tables(
    (T.book & T.author).on(T.book.author_id == T.author.id)
).columns(
    T.book.name, T.author.first_name, T.author.last_name
).where(
    (T.author.first_name != 'Tom') & (T.author.last_name != 'Smith')
)[20:30]
Out[31]: <QuerySet: SELECT "book"."name", "author"."first_name", "author"."last_name" FROM "book" INNER JOIN "author" ON ("book"."author_id" = "author"."id") WHERE "author"."first_name" <> %s AND "author"."last_name" <> %s LIMIT 10 OFFSET 20, ['Tom', 'Smith']>

Django integration.

Simple add "sqlbuilder.django_sqlbuilder" to your INSTALLED_APPS.

object_list = Book.s.q.tables(
    (Book.s & Author.s).on(Book.s.author == Author.s.pk)
).where(
    (Author.s.first_name != 'James') & (Author.s.last_name != 'Joyce')
)[:10]
BSD License

Author

Ivan Zakrevsky

Pip

sqlbuilder==0.7.9.4

Classifiers

  • Development Status :: 5 - Production/Stable
  • Intended Audience :: Developers
  • Operating System :: OS Independent
  • Programming Language :: Python
  • License :: OSI Approved :: BSD License
  • Topic :: Software Development :: Libraries :: Python Modules
File Type Python Version Uploaded On Downloads
sqlbuilder-0.7.9.4.tar.gz Source Aug. 10, 2015 430
Version Release Date
0.7.9.4 Aug. 10, 2015
0.7.9.3 May 17, 2015
0.7.9.2 May 17, 2015
0.7.9.1 May 6, 2015
0.7.9.0 April 18, 2015
0.7.8.0 March 30, 2015
0.7.7.7 Dec. 21, 2014
0.7.7.6 Nov. 21, 2014
0.7.7.5 Feb. 16, 2014
0.7.7.4 Jan. 29, 2014
0.7.7.3 Jan. 28, 2014
0.7.7.2 Jan. 10, 2014
0.7.7.1 Jan. 10, 2014
0.7.7 Jan. 6, 2014
0.7.6 Jan. 6, 2014
0.7.5 Dec. 8, 2013
0.7.4.3 Aug. 5, 2013
0.7.4.2 Aug. 4, 2013
0.7.4.1 Aug. 3, 2013
0.7.4 May 15, 2013
0.7.3 May 13, 2013
0.7.2 March 27, 2013
0.7.1 March 24, 2013
0.7 Aug. 25, 2015
Date Package Version Action
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.9.0 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.9.1 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.9.2 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.9.3 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.9.4 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.8.0 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.4.1 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.4.3 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.4.2 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.6 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.7 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.4 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.5 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.2 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.3 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7.1 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.1 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.3 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.2 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.5 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.4 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.7 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7.6 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder 0.7 Release Created
Aug. 25, 2015, 12:41 a.m. sqlbuilder Package Created