Skip to main content

A simple mysql orm base on pymysql

Project description

SimpySql

一个数据库orm, 目前支持mysql, mongodb

mysql文档 , mongo文档 , cassandra文档

安装

pip install simpysqls

初始化

你需要在你的项目根目录下创建一个.env文件,内容如下:

[default]                                       #数据库配置名称(对应model.__database__)
DB_TYPE=mysql                                   #数据库类型 mysql 或者 mongo
DB_HOST=127.0.0.1                               #数据库IP                          
DB_PORT=3306                                    #端口
DB_NAME=test_db1                                #库名
DB_USER=root                                    #账号
DB_PASSWORD=123456                              #密码
DB_CHARSET=utf8mb4                              #数据库编码
LOG_DIR=/home/logs/python/                      #开启日志, 日志路径: /home/logs/python/

[test_db2]                                      #其他的库
DB_TYPE=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=test_db2
DB_USER=root
DB_PASSWORD=123456
DB_CHARSET=utf8mb4
#LOG_DIR=/home/logs/python/                     #关闭日志

创建表model

创建数据库model 并继承simpysql.DBModel:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from simpysql.DBModel import DBModel

class ModelDemo(DBModel):
    
    __basepath__ = '/home/project/'             # .env 文件路径
    #__database__ = 'default'                   # 库选择, 没有该属性,则默认default库
    __tablename__ = 'lh_test'                   # table name
    __create_time__ = 'create_time'             # 自动添加创建时间字段create_time(精确到秒), 设置为None或者删除该属性,则不自动添加 
    __update_time__ = 'update_time'             # 自动更新时间字段update_time(精确到秒), 设置为None或者删除该属性,则不自动更新
    columns = [                                 # table columns
        'id',
        'name',
        'token_name',
        'status',
        'create_time',
        'update_time',
    ]

    # 可以通过该方法设置自动添加时间字段的格式
    # def fresh_timestamp(self):
    #     return datetime.datetime.now().strftime("%Y%m%d")

操作实例

ModelDemo.where('id', 4).select('id', 'name').take(5).get()

其他

欢迎志同道合的朋友一起参与本项目开发SQLServer、PostgreSQL开发, 联系方式: 490573621@qq.com

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

simpysqls-0.5.15.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpysqls-0.5.15-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file simpysqls-0.5.15.tar.gz.

File metadata

  • Download URL: simpysqls-0.5.15.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for simpysqls-0.5.15.tar.gz
Algorithm Hash digest
SHA256 b94698822ba17cc20475eb9e7d9bf2278356d805c3c2c27f4c6e1b83d3df64f5
MD5 52e9848de8843e0d870c978d97f04954
BLAKE2b-256 66971b12cd6b37276e50a781899c769fde5c84d109a4bc431ff038cce8203572

See more details on using hashes here.

File details

Details for the file simpysqls-0.5.15-py3-none-any.whl.

File metadata

  • Download URL: simpysqls-0.5.15-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for simpysqls-0.5.15-py3-none-any.whl
Algorithm Hash digest
SHA256 d134aedd9a5d5d21380da10b4206981714dc20f6111cb7f3b41c71e9d8f19b04
MD5 c116f357df7d95e833e5bea6747690f4
BLAKE2b-256 c48fbf5830a04937c648d48ee5163d39ce7feb07e241fd78cdef37dc0cf45f79

See more details on using hashes here.

Supported by

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