Skip to main content

mysqlx-generator is a model code generator from tables for MySqlx.

Project description

Install '''''''

.. code:: shell

pip install mysqlx-generator

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

.. code:: python

   from mysqlx.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 mysqlx.orm import Model, KeyStrategy

   class BaseModel(Model):
       __key__ = 'id'
       __del_flag__ = 'del_flag'
       __update_by__ = 'update_by'
       __update_time__ = 'update_time'
       __key_strategy__ = KeyStrategy.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 User(BaseModel):
       __table__ = 'user'

       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

MySqlx: https://pypi.org/project/mysqlx

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

mysqlx-generator-1.7.3.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file mysqlx-generator-1.7.3.tar.gz.

File metadata

  • Download URL: mysqlx-generator-1.7.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.2

File hashes

Hashes for mysqlx-generator-1.7.3.tar.gz
Algorithm Hash digest
SHA256 dfad4eeb94c59d549e1ba889e51d50b230a2a3b083999acf3913aca5c39ebae9
MD5 281dda90ad003af9ba605c6938cbf300
BLAKE2b-256 1dc95004e2f4cfd7fbe7c8e8875ce78a4d2d2ddf20688314260466924af2d302

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