About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
See full specifications

linux default iconSheba Publisher's description

Sheba SQL - SQL for normal people

Sheba offers SQL management for people that don't mind SQL.


I can write SQL faster than I can figure out the various library and ORM abstraction layers. Writing SQL directly in code is pretty disgusting. So I stole an idea from the Axamol SQL Library and along with a couple updates have created this library.

What is it?

First, we'll consider some basic query definitions:

name: create_roles_table
type: update
sql: |
scene text,
name text,
actor text,
UNIQUE(scene, name)
name: add_role
type: update
sql: |
INTO roles(scene, name, actor)
VALUES (${scene}, ${name}, ${actor})
name: list_roles
sql: |
SELECT name,
FROM roles
name ASC

This is a YAML file that defines a couple queries for working with a simple table that lists scenes, roles, and actors. This is the contents of the ./test/yaml/conn-queries.yaml that's used in a couple of the test cases in case you're curious.

Now, to use these in some code:

>>> import sheba
>>> lib = sheba.Library.from_file('test/yaml/conn-queries.yaml')
>>> conn = sheba.connect(lib, 'sqlite3', ':memory:')

Now that we have a connection, lets create the roles table:

>>> conn.u.create_roles_table()

The -1 is due to DDL statements not returning row information. I could technically create a third class of statement types so avoid this, but in the not doctest world you can just ignore that return value.

Next we'll insert a couple rows:

>>> conn.u.add_role(scene="Parrot Sketch", name="MR PRALINE", actor="John Cleese")
>>> conn.u.add_role(scene="Parrot Sketch", name="SHOP OWNER", actor="Machale Palin")
>>> conn.u.add_role(scene="Parrot Sketch", name="DEAD PARROT", actor="Fake Parrot")

Yep, it's that simple. And lastly, we'll list the roles in the table:

>>> for row in conn.q.list_roles():
... print "Name: %(name)s Actor: %(actor)s" % row
Name: DEAD PARROT Actor: Fake Parrot
Name: MR PRALINE Actor: John Cleese
Name: SHOP OWNER Actor: Machale Palin

As they say, "Wicked awesome."

Possible Query Attributes

The example above only used name, type, and sql. Only name and sql are absolutely required. The full list of attributes is:

* name - The name used to reference this query from Python

*desc - An explanation of the query for documentation.

* type - query or update. Defaults to query.

* dbs - A list of database names that this SQL will work with. The default

value is None which is interpreted as "Use this query when no SQL has been defined for the current connections database connection."

* sql - The actual query. SQL is passed through Mako with access to

any parameter names that were provide to the query. To bind a parameter in a query, simply print the value with standard Mako syntax like ${my_parameter_name}. Sheba will automatically replace it with the proper bind variable syntax and pass the supplied value onto the database connection.


It may appear at first glance that the dynamic queries are writing parameter values directly into the SQL. They are NOT. The actual values passed along into the template context are UUID's that will be replaced with bind parameters syntax appropriate to your database driver. If you're asking yourself, "What if I do want the actual value?" you should go fix all of your SQL injection vulnerabilities.

System Requirements:

В· Python
Program Release Status:
Program Install Support: Install and Uninstall

Sheba Tags:

Click on a tag to find related softwares

Is Sheba your software?

Manage your software

Most Popular

linux default icon A2Billing 1.6.0
A2Billing is a billing system interactive with Asterisk to give any Telecom company traditional offering VOIP... Read more
linux default icon FrontAccounting 2.3.10
FrontAccounting is free and released under the GNU General Public License.
linux default icon PgAdmin III for Linux 1.14.1
pgAdmin is the most popular and feature rich Open Source administration and development platform for... Read more
linux default icon RazorSQL for Linux 5.6.3
RazorSQL is an SQL query tool, database browser, SQL editor,....
linux default icon Salat Book 1.00
Salat / Namaz prayer database and tracking application