Coder Social home page Coder Social logo

mango's Introduction

mango

Python3 Mongodb ORM (开发中)

轻量级 Mongodb ORM。封装自 pymongo。

TODO

  • 动态添加所有方法
  • 有效封装find,支持直接迭代返回model对象
  • 支持连接多个库(db的保存方式)
  • 支持索引
  • 支持高级方法
  • 支持对更新等方法的验证

示例

from .mango import *

# 创建连接
conn, DB = connect(
    ip='127.0.0.1',
    port=27017,
    database='recommender'
)

# 声明Model
class Article(Model):
    class Meta():
        database = DB
        collection = 'article'
        index = [
            ('title', 1)
        ]

    # 不包含_id,由mongo自动生成
    id = IntField(unique=True)
    title = StringField()
    content = StringField()
    
# 查出一个    
doc = Article.find_one()

# 迭代查询
for doc in Article.find():
    # 将查出的字典转为Model对象
    print(Article(doc))
    
# 添加
_id = Article.create(
    id = 1
    title = 'test title'
    content = 'test_content'
)

# 添加(pymong原生)
_id = Article.insert({
    'id': 1
    'title': 'test title'
    'content': 'test_content'
})

# 更新(pymong原生)
Article.update(
    {
        'id': 1
    },{
        'id': 1,
        'title': 'test1',
        'content': 'test too',
    },
    # True表示upsert
    True
)

# 移除(pymongo原生)
Article.remove({'id': 1})

mango's People

Contributors

pingze-github avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.