pgsqlx-generator


Namepgsqlx-generator JSON
Version 1.7.4 PyPI version JSON
download
home_pagehttps://gitee.com/summry/pgsqlx/blob/master/generator.md
Summarypgsqlx-generator is a model code generator from tables for PgSqlx.
upload_time2024-03-29 02:32:57
maintainerNone
docs_urlNone
authorsummy
requires_python>=3.5
licenseNone
keywords postgresql pgsqlx python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Install
'''''''

.. code:: shell

   pip install pgsqlx-generator

Usage Sample
''''''''''''

.. code:: python

       from pgsqlx.generator import Generator

       if __name__ == '__main__':
           coder = Generator(host='127.0.0.1', port='3306', user='xxx', password='xxx', database='test')
           # you can generate a model class for one table
           coder.generate_with_tables(tables='user', path='models.py')
           # you can generate model classes for tables
           coder.generate_with_tables(tables=['user', 'person'], path='models.py')
           # you can generate model classes for all tables from a given schema. default current schema if not given
           coder.generate_with_schema(schema='test', path='models.py')

If you run last code, then generate a file 'models.py' in current
directory like follow:

.. code:: python

       from decimal import Decimal
       from datetime import date, datetime
       from pgsqlx.orm import Model, PkStrategy

       class BaseModel(Model):
           __pk__ = 'id'
           __del_flag__ = 'del_flag'
           __update_by__ = 'update_by'
           __update_time__ = 'update_time'
           __pk_strategy__ = PkStrategy.DB_AUTO_INCREMENT

           def __init__(self, id: int = None, create_by: int = None, create_time: datetime = None, update_by: int = None, update_time: datetime = None,
                   del_flag: int = None):
               self.id = id
               self.create_by = create_by
               self.create_time = create_time
               self.update_by = update_by
               self.update_time = update_time
               self.del_flag = del_flag


       class Person(BaseModel):
           __table__ = 'person'
           __key_seq__ = 'person_id_seq'

           def __init__(self, id: int = None, name: str = None, age: int = None, birth_date: date = None, sex: int = None, grade: float = None,
                   point: float = None, money: Decimal = None, create_by: int = None, create_time: datetime = None, update_by: int = None,
                   update_time: datetime = None, del_flag: int = None):
               super().__init__(id=id, create_by=create_by, create_time=create_time, update_by=update_by, update_time=update_time, del_flag=del_flag)
               self.name = name
               self.age = age
               self.birth_date = birth_date
               self.sex = sex
               self.grade = grade
               self.point = point
               self.money = money


PgSqlx: https://pypi.org/project/pgsqlx



            

Raw data

            {
    "_id": null,
    "home_page": "https://gitee.com/summry/pgsqlx/blob/master/generator.md",
    "name": "pgsqlx-generator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": "PostgreSQL, PgSqlx, python",
    "author": "summy",
    "author_email": "xiazhongbiao@126.com",
    "download_url": "https://files.pythonhosted.org/packages/c6/66/e41a4efdd0eb2b1ae7f853b18c144bd4de01c239f42db5305b03b23949da/pgsqlx-generator-1.7.4.tar.gz",
    "platform": null,
    "description": "Install\r\n'''''''\r\n\r\n.. code:: shell\r\n\r\n   pip install pgsqlx-generator\r\n\r\nUsage Sample\r\n''''''''''''\r\n\r\n.. code:: python\r\n\r\n       from pgsqlx.generator import Generator\r\n\r\n       if __name__ == '__main__':\r\n           coder = Generator(host='127.0.0.1', port='3306', user='xxx', password='xxx', database='test')\r\n           # you can generate a model class for one table\r\n           coder.generate_with_tables(tables='user', path='models.py')\r\n           # you can generate model classes for tables\r\n           coder.generate_with_tables(tables=['user', 'person'], path='models.py')\r\n           # you can generate model classes for all tables from a given schema. default current schema if not given\r\n           coder.generate_with_schema(schema='test', path='models.py')\r\n\r\nIf you run last code, then generate a file 'models.py' in current\r\ndirectory like follow:\r\n\r\n.. code:: python\r\n\r\n       from decimal import Decimal\r\n       from datetime import date, datetime\r\n       from pgsqlx.orm import Model, PkStrategy\r\n\r\n       class BaseModel(Model):\r\n           __pk__ = 'id'\r\n           __del_flag__ = 'del_flag'\r\n           __update_by__ = 'update_by'\r\n           __update_time__ = 'update_time'\r\n           __pk_strategy__ = PkStrategy.DB_AUTO_INCREMENT\r\n\r\n           def __init__(self, id: int = None, create_by: int = None, create_time: datetime = None, update_by: int = None, update_time: datetime = None,\r\n                   del_flag: int = None):\r\n               self.id = id\r\n               self.create_by = create_by\r\n               self.create_time = create_time\r\n               self.update_by = update_by\r\n               self.update_time = update_time\r\n               self.del_flag = del_flag\r\n\r\n\r\n       class Person(BaseModel):\r\n           __table__ = 'person'\r\n           __key_seq__ = 'person_id_seq'\r\n\r\n           def __init__(self, id: int = None, name: str = None, age: int = None, birth_date: date = None, sex: int = None, grade: float = None,\r\n                   point: float = None, money: Decimal = None, create_by: int = None, create_time: datetime = None, update_by: int = None,\r\n                   update_time: datetime = None, del_flag: int = None):\r\n               super().__init__(id=id, create_by=create_by, create_time=create_time, update_by=update_by, update_time=update_time, del_flag=del_flag)\r\n               self.name = name\r\n               self.age = age\r\n               self.birth_date = birth_date\r\n               self.sex = sex\r\n               self.grade = grade\r\n               self.point = point\r\n               self.money = money\r\n\r\n\r\nPgSqlx: https://pypi.org/project/pgsqlx\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "pgsqlx-generator is a model code generator from tables for PgSqlx.",
    "version": "1.7.4",
    "project_urls": {
        "Homepage": "https://gitee.com/summry/pgsqlx/blob/master/generator.md"
    },
    "split_keywords": [
        "postgresql",
        " pgsqlx",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c666e41a4efdd0eb2b1ae7f853b18c144bd4de01c239f42db5305b03b23949da",
                "md5": "839a75587ee357aef953d40cfa28facf",
                "sha256": "4d156cffc17edc8f7e4678f99de9f92a8c5a5529d876ec101ad24f1f38675f09"
            },
            "downloads": -1,
            "filename": "pgsqlx-generator-1.7.4.tar.gz",
            "has_sig": false,
            "md5_digest": "839a75587ee357aef953d40cfa28facf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 5276,
            "upload_time": "2024-03-29T02:32:57",
            "upload_time_iso_8601": "2024-03-29T02:32:57.470139Z",
            "url": "https://files.pythonhosted.org/packages/c6/66/e41a4efdd0eb2b1ae7f853b18c144bd4de01c239f42db5305b03b23949da/pgsqlx-generator-1.7.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 02:32:57",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pgsqlx-generator"
}
        
Elapsed time: 0.18767s