[Preview] SQLighter – the easiest open source SQLite3 wrapper

If you use SQLite in your software regularly you are most likely annoyed by the repetitive task you must do every time.

  • Create the database structure with dozens of SQL commands
  • Create queries
  • care about updating or inserting values
  • make commits at the end

On the other hand, you do not want to miss the power that you get with a database (like automatic rollbacks when something went wrong).

Here comes SQLighter to make the programmer’s life as easy as never before (for simple tasks you do not even need to know a single SQL command)

With 3 lines of code, you create a new database:

	
	header = { 'id': int , 'name': str, 'time': int}

	with SQLighter('test.db',"Table 1",header,autoincrement=True) as db:
        pass
    

If Table 1 does not exist it is created automatically based on the datatypes in the header dict.

You do not even have to specify the datatypes. This works as well 😎:

	
	header = { 'id': 0 , 'name': "", 'time': 0}
	

Let us add some data to the database:

	
	header = { 'id': int , 'test_id': int, 'time': int}
	data = { 'test_id': int, 'time': int}

	with SQLighter('test.db',"Table 1",header,True) as db:
		for i in range(0,1000000):
			data['test_id'] = i
			data['time'] = time.time()
			db + data

To achieve the best performance, the commit is done automatically only once at the end.

Ok, adding was easy, but a query must be more painful, mustn’t it?

It is more fun than ever before:

	
	with SQLighter('test.db',"Table 1",header,True) as db:
	    r = db.query()
		for i in r:
			print(i)

As a nice extra the structure is returned as a named dictionary with field names from the database.

No unreadably code like this anymore

 print (i[0],i[3])

Instead you can write:

 print (i["id"], i["time"])

Ok, we know you are one of the cool kidz and you want to use real SQL like grown ups. Put on your big girl’s / boy’s pants and you can do this:

	
	with SQLighter('test.db',"Table 1",None,False) as db:

		for i in db.set_custom_query("select * from 'Table 1' where id < 1000 limit 5 offset 10"):
			print (i)
			

For a query you do not even need to know the database structure! Everything is done for you inside the library.

Release version of SQLighter will be released on: 2021-03-15

Download latest preview

4 thoughts on “[Preview] SQLighter – the easiest open source SQLite3 wrapper

    • irmo Post authorReply

      SQL operations are a perfect candidate for async io. Will certainly be supported in a future version.

Leave a Reply to irmo Cancel reply

Your email address will not be published. Required fields are marked *