LPX55 / ssqlite3

A simple wrapper around Deta Base to use SQLite3 in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ssqlite3

Installation

pip install git+https://github.com/jnsougata/ssqlite3.git

Usage

from ssqlite3 import SQLBase

# Create a database
db = SQLBase(
    db_name="sqldb", 
    project_key="collection_key"
)
db.connect()
# Create a table and insert some data
db.conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
db.conn.execute("INSERT INTO users (id, name, age) VALUES (1, 'John', 25)")
db.conn.execute("INSERT INTO users (id, name, age) VALUES (2, 'Jane', 22)")
db.conn.execute("INSERT INTO users (id, name, age) VALUES (3, 'Bob', 30)")
db.conn.execute("INSERT INTO users (id, name, age) VALUES (4, 'Alice', 27)")
db.commit()
# Add new attr to the table
db.conn.execute("ALTER TABLE users ADD city TEXT")
db.commit()
# Update data
db.conn.execute("UPDATE users SET city='New York' WHERE id=1")
db.commit()
# print all the users with name starting with J
users = db.conn.execute("SELECT * FROM users WHERE name LIKE 'J%'").fetchall()
print(users)
  • don't forget to commit the changes after doing a bunch of oprations.

About

A simple wrapper around Deta Base to use SQLite3 in Python

License:MIT License


Languages

Language:Python 100.0%