项目作者: ThinkEE

项目描述 :
Asynchronous ORM (Object Relational Mapper) for Twisted
高级语言: Python
项目地址: git://github.com/ThinkEE/Kameleon.git
创建时间: 2017-06-19T15:24:58Z
项目社区:https://github.com/ThinkEE/Kameleon

开源协议:MIT License

下载


Kameleon

Kameleon is a small async ORM built over Twisted.

  • Small ORM
  • Written in python with support for versions 2.6+
  • Built-in support for Postgresql

Examples

Layout

  1. from twisted.internet.defer import inlineCallbacks, returnValue
  2. import databases
  3. from model import fields, Model, BaseModel
  4. db_name = "ORMdatabase" # Database name
  5. user = "user" # User name
  6. password = "password" # Password
  7. DATABASE = databases.PostgresqlDatabase(db_name, user=user, password=password)
  8. __all__ = ["Test1"]
  9. class Test1(Model):
  10. class Meta:
  11. database = DATABASE
  12. code = fields.CharField(max_length=50)
  13. user_id = fields.IntegerField()

Usage

  1. test1s = yield (baseModels.Test1.all()
  2. .where((baseModels.Test1.code == "code1") | (baseModels.Test1.code == "code2"), baseModels.Test1.user_id == 1 ).execute())
  3. if test1s[0]:
  4. for test in test1s:
  5. print(test.dictValues)

Installation

Set up the environment

  • Virtualenv

    • Install virtualenv
    • Create virtualenv virtualenv Kameleon
    • Go to environment cd Kameleon
    • Activate it source bin/activate
  • Clone repository git clone https://github.com/ThinkEE/Kameleon.git

  • Go to folder cd Kameleon

Install dependencies

  • Run pip install -r requirements.txt

Run code

You can run the templates in order to test it python run_templates.py
There are two different commands you can us:

  • python run_templates.py --reset Resets the Database
  • python run_templates.py --create Creates tables