Skip to main content

✨ Awesome databases framework that shines ✨

Project description

✨ Awesome databases framework that shines ✨

Version License pypi total downloads GitHub last commit

Breaking changes ⚙ 🔑 🎉 🎠 ❌

  • easy to use: lots of out-of-the-box methods.
  • less bug: not like others, I don't want to name it, and if you unluckily enough to encounter, it's easy to solve by yourself.

Installation ⚙🙈

pip install sqlstar

if you need help

sqlstar -h

Tips and tricks ✅

Guides 📝

for now, there is only mysql backend...

connection

import sqlstar

# driver://user:passwd@host:port/dbname
mysql = sqlstar.Database('mysql://root:***@localhost/tmp')
mysql.connect()

Query

QUERY = '''
    SELECT *
    FROM Girls
    WHERE AGE BETWEEN 20 AND 24
        AND BOYFRIEND IS NULL
    ORDER BY WHITE, RICH, BEAUTY DESC;
'''

Fetch data, and format result into Dataframe

df = mysql.fetch_df(QUERY)

Fetch all the rows

data = mysql.fetch_all(QUERY)

Fetch several rows

data = mysql.fetch_many(QUERY, 3)

Execute

mysql.execute("""
    CREATE TABLE `users` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `email` varchar(255) COLLATE utf8_bin NOT NULL,
        `password` varchar(255) COLLATE utf8_bin NOT NULL,
        PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
    AUTO_INCREMENT=1 ;
    """)

Insert

Insert many records

mysql.insert_many(table, data, cols)

Insert Dataframe type of data

mysql.insert_df(table, df)

Export

Export result to csv

mysql.export_csv(query, fname, sep)

Export result to excel

mysql.export_excel(query, fname)
Nice Features ✨

Create table

mysql.create_table(
    "users",
    comments={
        "name": "姓名",
        "height": "身高",
        "weight": "体重"
    },
    dtypes={
        "varchar(30)": [
            "name",
            "occupation",
        ],
        "float": ["height", "weight"],
        "int": ["age"],
    },
)

if you have data, you can make it more simple, just like this

mysql.create_table("users", df)

if you only want to specify some of them

mysql.create_table(
    table='news_spider',
    df=df,
    comments={
        "create_time": "插入时间",
        "title": "标题",
        "content": "正文",
        "author": "作者",
        "publish_time": "发布时间",
        "read_num": "阅读量",
    },
    # if type is not given, sqlstar will automatically inference
    dtypes={
        "datetime": ["create_time", "publish_time"],
        "longtext": ["content"],
        "varchar(100)": ["title", "author"],
        "decimal(10, 3)": ["read_num"]
    })

You don't need to fill in everything, and you just need to fill in comment or data type that you want to specify, then sqlstar will do the rest for you.

Rename table

mysql.rename_table(table, name)

Rename column

mysql.rename_column(table, column, name, dtype)

Add new column

mysql.add_column(table, column, dtype, comment, after)

Add comment for table

mysql.add_table_comment(table, comment)

Change column's attribute

mysql.change_column_attribute(table, column, dtype, notnull, comment)

Set primary key

mysql.add_primary_key(table, primary_key)

Truncate table's data, but keep the table structure

mysql.truncate_table(table)

Drop table

mysql.drop_table(table)

Drop column

mysql.drop_column(table, column)

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

sqlstar-3.1.4.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

sqlstar-3.1.4-py2.py3-none-any.whl (44.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sqlstar-3.1.4.tar.gz.

File metadata

  • Download URL: sqlstar-3.1.4.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for sqlstar-3.1.4.tar.gz
Algorithm Hash digest
SHA256 d0b20818e194885e091358d2c7029f2e81c8e7373b1d866fe906bea3526e4354
MD5 0cc9e75a33370694e724155a732c2842
BLAKE2b-256 ad3372061d425fccd3ecc7ae022f86664c30a06de58580aa19792edb47552afb

See more details on using hashes here.

File details

Details for the file sqlstar-3.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: sqlstar-3.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 44.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for sqlstar-3.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2ec35457eeb19ad73bf1cc99a76ca8e111c8431c6f8e69cfd190bdfdcffa5217
MD5 bb25909d0c8867aefa0a7c2d2b4710ca
BLAKE2b-256 573f0c9ce3f5f496f4cc4e78d2286d4f87aff4944a2fc9ad4a1f6ed004b35112

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