Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

a little database access interface

Project description

Introduction

This is a vary simple database access interface for python.

Feature

  • Easy to use
  • supports sqlite, mysql

Download

Go to the homepage: http://github.com/jander/littlesql/

Example

example table: foo (id int, name string)

Connect

connect to sqlite3

ctx =  SqliteContext("test.db")
db = Database(ctx)

connect mysql

ctx = MySqlContext(username="name", password="pwd", hostname="localhost", db="test")
db = Database(ctx)

Query

query a row dict

db.foo("name=?", "tom").get()

# raw sql
db.get("select * from foo where name=?", "tom")

query many rows

db.foo("id>?", 100).orderby("id desc").limit(0,10).query()

# raw sql
db.query("select * from foo where id>? order by id desc limit 0,100;", 100)

query selected cols

db.foo.query("id, name")

# raw sql
db.query("select id, name from foo")

Update

fdict = dict(name="new foo")
db.foo("id=?", 1).update(**fidct)

# raw sql
db.execute("update foo set name=? where id=?", "new foo", 1)

Delete

db.foo("name like ?", "test%").delete()

# raw sql
db.execute("delete from foo where name like ?", "test%")

Other

see the test code.

Reference

Project details


Release history Release notifications

This version

0.1

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page