Skip to content

Latest commit

 

History

History
104 lines (92 loc) · 2.11 KB

README.md

File metadata and controls

104 lines (92 loc) · 2.11 KB

imgage

Yunorm is a small ORM.

  • a small ORM but It's very practical
  • python3.5 and 3.6 (developed with 3.5)
  • support mysql, support mysql connections pool
  • can help you to maintenance the DB connection
  • support to create multiple database connections

Requirements

  • mysqlclient==1.3.14

Install

  • pip install yunorm

or

  • git clone git@github.com:yunsonbai/yunorm.git
  • python setup.py install

Quick Start

example

note

If you want to use yunorm, the table that you will operate on must be exist in DB.

Documentation

  • field

    • Prikey
    • CharField
    • IntegerField
    • DateTimeField
    • DecimalField
  • filter operator

    • lt: '<'
    • gt: '>'
    • une: '!='
    • lte: '<='
    • gte: '>='
    • in: 'in'
  • function

    • filter
    • create
    • update
    • delete
    • limit
    • order_by
    • group_by
    • desc_order_by
    • first
    • all
    • count
  • note if you want to get db data, you need call data() in the end

  res = TestModel.objects.filter(**select_term).all().data()
  res = TestModel.objects.filter(**select_term).limit(0, 10).data()
  res = TestModel.objects.filter(
    **select_term).order_by(id).limit(0, 7).data()
  • Get Data
  select_term = {
    "zan_num__gt": 0,
    "id__gt": 3700000
  }
  res = TestModel.objects.filter(**select_term).all().data()
  feed = TestModel.objects.filter(id=3700000).first().data()
  • Create Data
  def test_create_orm(i):
    create_data = {
      'label': 1,
      'title': 'test_{0}'.format(i)
    }
    TestOrm.create(**create_data)
  • Update Data
  def test_update_orm():
    update_data = {
      'title': 'hello yunsonbai',
      'label': 10
    }
    res = TestOrm.objects.filter(id__in=[1, 2]).data()
    for r in res:
      r.update(**update_data)
    # or
    res = TestOrm.objects.filter(id=3).first().data()
    res.update(**update_data)
  • Delete Data
  def test_delete_orm():
    res = TestOrm.objects.filter(id__in=[7, ]).data()
    for r in res:
      result = r.delete()
      print(result)