Skip to main content

SmartSQL - lightweight sql builder.

Project description

SmartSQL - lightweight Python sql builder, follows the KISS principle, less than 60 Kb. Supports Python2 and Python3.

You can use SmartSQL separatelly, or with Django, or with super-lightweight Ascetic ORM, or with super-lightweight datamapper Openorm (miror) etc.

LICENSE:

  • License is BSD

Quick start

>>> from sqlbuilder.smartsql import Q, T, compile
>>> compile(Q().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])
('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 %s OFFSET %s', ['Tom', 'Smith', 10, 20])

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]

More info

See docs on http://sqlbuilder.readthedocs.org/

P.S.: See also article (in Russian) about SQLBuilder.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlbuilder-0.7.9.44.tar.gz (48.2 kB view details)

Uploaded Source

File details

Details for the file sqlbuilder-0.7.9.44.tar.gz.

File metadata

  • Download URL: sqlbuilder-0.7.9.44.tar.gz
  • Upload date:
  • Size: 48.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sqlbuilder-0.7.9.44.tar.gz
Algorithm Hash digest
SHA256 7446d78c757f709798c2122b4b33f618007e078183375d7112a6b9cf32cf4067
MD5 f312f365afe3bfd8c4586c160f36c2f0
BLAKE2b-256 d257926d8da7ef4cb077b5ac17bf6848dafc83b7903d158162d5be6415d34cfd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page