Skip to content
/ que_so Public

Que-so is a fast, easy and simple way for make CRUD.

Notifications You must be signed in to change notification settings

hel-o/que_so

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Que_so

Que-so is a fast, easy and simple way for make CRUD, perfect for write proof of concepts in a fast way and other small applications using sqlite as database, all in a single file and with no third dependencies than the Python Standard Library.

The idea is make CRUDs in a quick and easy way possible, define your class and let Que_so take care to keep data on db, you can use sql statements almost directly so you have control of what you want to bring and do.

Example:

from que_so import Model

class StaffForm(Model):
    name = Model.text
    email = Model.text
    pay = Model.real
    admission = Model.datetime
    active = Model.boolean


staff_form = StaffForm()
staff_form.name = 'Wilson C.'
staff_form.email = '[email protected]'
staff_form.pay = 99000.99
staff_form.admission = datetime.now()
staff_form.active = True

And simplement save it on db:

staff_id = staff_form.save()

Get values:

items = StaffForm.select().all()
for item in items:
    print item

Also you can filter and get specific columns:

items = StaffForm.select('name, email').filter(
    where='admission > "1992-02-01" AND active = 1'
)

When you make updates it only takes variables with values, for example:

staff_form = StaffForm()
staff_form.pay = 99999
rows = staff_form.update(
    where='rowid = {}'.format(staff_id)
)
print 'rows affected: ', rows

In this case only the column 'pay' will be taken:

UPDATE staff SET pay=9999 WHERE rowid = 1

Delete records:

rows = StaffForm.delete(
    where='rowid = {}'.format(staff_id)
)

###Pro tip You can specify the name of the table or the database:

__database__ = '/tmp/company.db'
__table__ = 'staff'

Example:

class StaffForm(Model):
    __database__ = '/tmp/company.db'
    __table__ = 'staff'

About

Que-so is a fast, easy and simple way for make CRUD.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages