Skip to main content

A fork of sqlite-utils with CLI etc removed

Project description

sqlite-minutils

[!TIP]

Where to find the complete documentation for this library

If you want to learn about everything this project can do, we recommend reading the Python library section of the sqlite-utils project here.

This project wouldn’t exist without Simon Willison and his excellent sqlite-utils project. Most of this project is his code, with some minor changes made to it.

Install

pip install sqlite-minutils

Use

First, import the sqlite-miniutils library. Through the use of the all attribute in our Python modules by using import * we only bring in the Database, Queryable, Table, View classes. There’s no risk of namespace pollution.

from sqlite_minutils.db import *

Then we create a SQLite database. For the sake of convienance we’re doing it in-memory with the :memory: special string. If you wanted something more persistent, name it something not surrounded by colons, data.db is a common file name.

db = Database(":memory:")

Let’s drop (aka ‘delete’) any tables that might exist. These docs also serve as a test harness, and we want to make certain we are starting with a clean slate. This also serves as a handy sneak preview of some of the features of this library.

for t in db.tables: t.drop()

User tables are a handy way to create a useful example with some real-world meaning. To do this, we first instantiate the users table object:

users = Table(db, 'Users')
users
<Table Users (does not exist yet)>

The table doesn’t exist yet, so let’s add some columns via the Table.create method:

users.create(columns=dict(name=str, age=int))
users
<Table Users (name, age)>

What if we need to change the table structure?

For example User tables often include things like password field. Let’s add that now by calling create again, but this time with transform=True. We should now see that the users table now has the pwd:str field added.

users.create(columns=dict(name=str, age=int, pwd=str), transform=True)
users
<Table Users (name, age, pwd)>
print(db.schema)
CREATE TABLE "Users" (
   [name] TEXT,
   [age] INTEGER,
   [pwd] TEXT
);

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlite-minutils-3.37.0.post2.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

sqlite_minutils-3.37.0.post2-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file sqlite-minutils-3.37.0.post2.tar.gz.

File metadata

File hashes

Hashes for sqlite-minutils-3.37.0.post2.tar.gz
Algorithm Hash digest
SHA256 7546be2fb688480c82194588255629091e92b176080f6568b72d7a23ad7784d4
MD5 57b2e42c589752e2a9eb35cf4e879607
BLAKE2b-256 4f4cc1e32b23f14b1e09c2c11103ab117d96f5d351da31ce944ebba7ada81b38

See more details on using hashes here.

File details

Details for the file sqlite_minutils-3.37.0.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlite_minutils-3.37.0.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 9483990440328d2055783bb4496bf4caa1c4bc1536b65bb5f62f6b5c3d671ee7
MD5 7e62ec59e5bb941094e036c26f2941a1
BLAKE2b-256 6bbdb47949ab09121bfd0188259be2c7949ba4ad02b63690f1fc3da9984cf6f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page