Package: micropg-lite
micropg_lite (The worlds lightest PostgreSQL driver for micropython)A MicroPython PostgreSQL database driver made for microcontrollers (specifically for ESP8266) that are low on RAM.Difference betweenmicropg_liteandmicropgmicropg_liteis a lightweight version based onmicropgbynakagami. If you have RAM/memory issues withmicropgthan this library might solve this issue.Themicropg_litelibrary has some limitations in functionality due to the lightweight.For more information, seemicropg_lite-sql-handling-and-restrictionsInstallationDownload themicropg_lite.pyfile fromgithub.comorpypi.orgto your local computer.Copy themicropg_lite.pyfile to the "/lib" folder on the microcontroller using the Thonny IDE or another program. If there is no "lib" folder in the root directory, you have to create it.Hintfor the Thony IDE:Open in the top bar the "View" menu and make sure that the entry "Files" has a "âœ“", if not then click on "Files". Now you can directly download and upload files from your computer to the microcontroller. You also can create folders on the microcontroller.Now you should be able to import the library to your microcontroller in a MicroPython file.importmicropg_liteIf there are problems or questions, open an issue ongithub.com.microcontroller file tree/
|- example.py
|- lib/
    |- micropg_lite.pyExamplesYou need to establish a network connection before executing micropg_lite code. TheSELECT exampleinclueds the wifi template. All other examples do not include the wifi template.examples/ folder ongithub.comThe examples/ folder includes the database sql script which was used to create the database and the used data in all those examples. The examples folder also includes the full scripts used in this readme including the wifi connection template.SELECT example with wifi connection:importnetwork# Handles the wifi connectionimportmicropg_lite### To Do: Fill in your wifi connection data and change the server datassid='wifissid'# replace the string with your wifi ssidpassword='secret'# replase tge string with your wifi password# Connect to networkwlan=network.WLAN(network.STA_IF)wlan.active(True)wlan.connect(ssid,password)print("Wifi connected")conn=micropg_lite.connect(host='127.0.0.1',# replace the string with your server ip-addressuser='postgres',# replace the string with your userpassword='123456',# replace the string with your passworddatabase='exampledatabase')cur=conn.cursor()cur.execute('select * from customers')selectresult=cur.fetchall()conn.close()# EXAMPLE: Print raw dataprint(selectresult)# EXAMPLE: Print data tableforr1inselectresult:forr2inr1:print(r2,end="\t")print()INSERT exampleconn=micropg_lite.connect(host='127.0.0.1',# replace the string with your server ip-addressuser='postgres',# replace the string with your userpassword='123456',# replace the string with your passworddatabase='exampledatabase')cur=conn.cursor()cur.execute('INSERT INTO customers (id, firstName, lastName, email) values (%s,%s,%s,%s)',['5','David','Wilson','david.wilson@example.com'])conn.close()UPDATE exampleconn=micropg_lite.connect(host='127.0.0.1',# replace the string with your server ip-addressuser='postgres',# replace the string with your userpassword='123456',# replace the string with your passworddatabase='exampledatabase')cur=conn.cursor()cur.execute('update customers set firstName=\'UpdatedFirstName\'where id=2;')conn.close()DELETE exampleconn=micropg_lite.connect(host='127.0.0.1',# replace the string with your server ip-addressuser='postgres',# replace the string with your userpassword='123456',# replace the string with your passworddatabase='exampledatabase')cur=conn.cursor()cur.execute('delete from customers where id=1;')conn.close()micropg_lite sql handling and restrictionsYou have to put IDs into ' '. For example, see the IDs in the `insert exampleEscape parameters are not always working. You may have to change your queries. For example, take a look at the sql query used in theupdate exampleYou can only commit. Rollback is inmicropg_litenot supportedYou can only execute INSERT, SELECT, UPDATE and DELETE statementsYou cannot execute "CREATE DATABASE" or "DROP DATABASE" queriesNot support for array data types.Not support for prepared statements.