Skip to main content

connect to database

Project description

database操作(支持 mysql mongodb)

How to use

mysql

mongodb

elasticSearch

sqlite3

创建表

from pydb3.db import Db
from pydb3.model import Integer, VarChar, Model, Float, Date, DateTime

'''定义模型'''


class Student(Model):
    name = VarChar(length=12, null=False, primary=False, comment="姓名")
    age = Integer(length=2, null=False, default=18, comment="年龄")
    score = Integer(length=11, null=False, default=10, comment="分数")
    mark = Integer(length=12, default=0, auto=True, null=False, primary=True, comment="标签")
    date = Date(length=12, default=0, null=False, auto=True, primary=False, comment='日期')
    create_time = DateTime(default=None, null=False, auto=True, comment="时间")

    def __init__(self, name='test', age=None, mark=None, date=None, create_time=None):
        self.name = name
        self.age = age
        self.mark = mark
        self.date = date
        self.create_time = create_time


if __name__ == '__main__':
    # 设置数据源
    db = Db()
    Student.set_db(db)
    s = Student()
    # 创建表
    s.create_table()
    # 将s的属性插入数据库
    s.save()

新增数据

db = Db()
datas = [None, '小明', 12]
'''相当于 insert into table values(NULL,'小明',12)'''
db.insert('table', datas)

查询

db = Db()
'''相当于 select * from table where name=1 and age=1 limit 0,100'''
db.select("table").where(name=1).and_(age=1)[0:100].execute()

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

pydb3-0.0.4.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

pydb3-0.0.4-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file pydb3-0.0.4.tar.gz.

File metadata

  • Download URL: pydb3-0.0.4.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for pydb3-0.0.4.tar.gz
Algorithm Hash digest
SHA256 8176ec3b5892f0d2211e809ca93a0fa3796c66290f9e7966f531a4d49354d426
MD5 a71e58c6139cd575206c0879eab61088
BLAKE2b-256 873c8d0fdec3b18a06fcb776f1b9b996f8dc5c55ca45fbc8d59338e64e290a7c

See more details on using hashes here.

File details

Details for the file pydb3-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pydb3-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for pydb3-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 85a7cb744f65489b3c03dd9cb16d0331b84f8715d202cc2440fc470c8d855e1f
MD5 592209879de70e57b1ea82dd3d7a50ab
BLAKE2b-256 ef57adc8eaca2d98a5da4f66d6b8a36c84f8b65699efbc15dcddb74a1924dc7f

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