sqlsy


Namesqlsy JSON
Version 1.1.0 PyPI version JSON
download
home_page
SummaryFill your database Quickly with dummy data
upload_time2023-04-27 14:16:27
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords sql sql dummy data fake data
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sqlsy
![badge4](https://img.shields.io/badge/MIT-License-red)
![badge3](https://img.shields.io/badge/version-v1.0.0-magenta)
![badge1](https://img.shields.io/static/v1?label=python%203&message=SQL&color=blue)
![badge2](https://img.shields.io/static/v1?label=easy&message=install&color=green)

A simple Python Module to easy fill your sql tables with data.

## Install
```bash
pip install sqlsy
```

## Quick Usage
A simple script to fill in data inside of a mysql table

```python
from sqlsy import Engine
from sqlsy import Int, VarChar      # sql datatypes to define schema

# config for mysql connection : uses mysql api inside
config = {
  'user':'username',
  'password':'pas@word',
  'host':'localhost',
  'database':'dbName'   # database to use: optional as it can be selected using a method
}

# custom function should be a generator
def get_id(n1, n2):
  i = n1
  while i < n2:
    yield i
    i += 1

# define the schema of the table to fill
# hook specifies what data to generate
schema = {
  'id':Int(custom_func=get_id(0,30)),     # generates numbers 0 - 30 including 30
  'name':VarChar(hook='name'),        # here generate fake names
  'ph_number':VarChar(hook='phone_number')           # here generate fake jobs
}


# create engine instance
engine = Engine(config)

# ASSUMING that the table is already created
# call the method to fill in the table
# 101 rows as id can take values from 0 to 30 = 31
engine.fill_table("person", schema, 31)       # give it tablename, schema of table and no of rows.

# print the table if you want
engine.print_table("table_name")

# close the connection
engine.close()
```

## API provided by Engine Class
The API include following methods and attributes:
Let the `engine` be an instance of `Engine` class
```python
engine = Engine(config)
```
### Attributes
- `engine.config` : Stores the provided config for mysql api connection
- `engine.conn` : It is what stores the connection object after connection is opened.
- `engine.cursor` : It stores the cursor to execute queries on the database.

## Methods
- `engine.fetch(table_name, [col_name1, col_name2])` : Grab the data from the specified columns directly

- `engine.create_db(database_name)` : Creates a database with name as provided in argument.

- `engine.create_table(table_name, schema)` : Creates a table with the specified Schema.

- `engine.drop_db(db_name)` : Drops the database if it exists

- `engine.drop_table(tb_name)` : Drops the table if it exists

- `engine.fill_table(tb_name, tb_schema, n_rows)` : Fills the table with tb_name as name and tb_schema as schema with n_rows of data. Make sure the provided hooks or custom_functions generate equal to or more than n_rows of data.

- `engine.print_table(tb_name)` : It prints the table in pretty format for you to see.

- `engine.clear_table(tb_name)` : It removes all the data from the table with provided table name

- `engine.close()` : It closes the connection to the database. If not called, the connection will be closed when `engine` object is destroyed.

# Schema Functions to specify datatypes

### How to Describe Schema
> Schema can be describe by using the provided functions which are documented below:

1. `Int` - means "INT" of SQL.

2. `Float` - means "Float" of SQL. Doesnt support size and pricision as recommended by the Mysql docs.

3. `Char` - means "CHAR" of SQL. By default of size 255.

4. `VarChar` - means "VARCHAR" of SQL. By default of size 255 # does not take size like in SQL.

### Equivalent to SQL counterparts
`Date`, `DateTime`, `Time`, `Timestamp`

# How Data is Generated
This module is designed such that the below provided hooks actually are mapped to functions which are responsible for data generation.

Below are the Hooks which can be used to generate data automatically, also Custom Generator functions can be provided which will then be called to generate data.


### Hooks for Int / Float type data
`random_int` : generates random integers - provide range with arguments
```python
# schema description
tb_name = {
  'age':Int(hook='random_int', args=(10,50))
}
```

`random_digit` : generates random 0-9 digit.

`random_float` : generates random float value in the range given in args.

```python
schema = {
  'id':Float(hook='random_float', args=(50,200))
}
```

`sequence` : generates sequenctial numbers from the range given using `args`.

```python
schema = {
  'id':Int(hook='sequence', args=(50,100))
}
```

`random_choice` : Randomly chooses values from a given list
```python
schema = {
  'stream':VarChar(hook='random_choice', args=(['bca', 'btech', 'commerce', 'mtech']))
}
```

### Hooks for VarChar / Char type data
`name` : generates full names

`first_name` : generates first names

`email` : generates emails

`last_name` : generates last names

`address` : generates fake addresses

`male_name` : generates male names

`female_name` : generates female names

`job`: generates a job name

`phone_number` : generates phone numbers

`md5` : Generates fake md5 hashes

`sha1` : Generates sha1 hashes

`uuid` : Generates UUID's


### Hooks for Date/DateTime/Time/Timestamp type data

`future_datetime` : generates a future datetime

`past_datetime` : generates a past datetime

`future_date`: generates a future date

`past_date` : generates a past date

`time` : generates time value HH:MM:SS

`date`: generates date value

`date_of_birth` : generates dob's in YYYY-MM-DD format

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sqlsy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "sql,sql dummy data,fake data",
    "author": "",
    "author_email": "shoaib wani <shoaibwani010@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/57/57/20c35bf9deccb059364064571ee881cc4c967092a761db3b9cad8970e3e7/sqlsy-1.1.0.tar.gz",
    "platform": null,
    "description": "# sqlsy\n![badge4](https://img.shields.io/badge/MIT-License-red)\n![badge3](https://img.shields.io/badge/version-v1.0.0-magenta)\n![badge1](https://img.shields.io/static/v1?label=python%203&message=SQL&color=blue)\n![badge2](https://img.shields.io/static/v1?label=easy&message=install&color=green)\n\nA simple Python Module to easy fill your sql tables with data.\n\n## Install\n```bash\npip install sqlsy\n```\n\n## Quick Usage\nA simple script to fill in data inside of a mysql table\n\n```python\nfrom sqlsy import Engine\nfrom sqlsy import Int, VarChar      # sql datatypes to define schema\n\n# config for mysql connection : uses mysql api inside\nconfig = {\n  'user':'username',\n  'password':'pas@word',\n  'host':'localhost',\n  'database':'dbName'   # database to use: optional as it can be selected using a method\n}\n\n# custom function should be a generator\ndef get_id(n1, n2):\n  i = n1\n  while i < n2:\n    yield i\n    i += 1\n\n# define the schema of the table to fill\n# hook specifies what data to generate\nschema = {\n  'id':Int(custom_func=get_id(0,30)),     # generates numbers 0 - 30 including 30\n  'name':VarChar(hook='name'),        # here generate fake names\n  'ph_number':VarChar(hook='phone_number')           # here generate fake jobs\n}\n\n\n# create engine instance\nengine = Engine(config)\n\n# ASSUMING that the table is already created\n# call the method to fill in the table\n# 101 rows as id can take values from 0 to 30 = 31\nengine.fill_table(\"person\", schema, 31)       # give it tablename, schema of table and no of rows.\n\n# print the table if you want\nengine.print_table(\"table_name\")\n\n# close the connection\nengine.close()\n```\n\n## API provided by Engine Class\nThe API include following methods and attributes:\nLet the `engine` be an instance of `Engine` class\n```python\nengine = Engine(config)\n```\n### Attributes\n- `engine.config` : Stores the provided config for mysql api connection\n- `engine.conn` : It is what stores the connection object after connection is opened.\n- `engine.cursor` : It stores the cursor to execute queries on the database.\n\n## Methods\n- `engine.fetch(table_name, [col_name1, col_name2])` : Grab the data from the specified columns directly\n\n- `engine.create_db(database_name)` : Creates a database with name as provided in argument.\n\n- `engine.create_table(table_name, schema)` : Creates a table with the specified Schema.\n\n- `engine.drop_db(db_name)` : Drops the database if it exists\n\n- `engine.drop_table(tb_name)` : Drops the table if it exists\n\n- `engine.fill_table(tb_name, tb_schema, n_rows)` : Fills the table with tb_name as name and tb_schema as schema with n_rows of data. Make sure the provided hooks or custom_functions generate equal to or more than n_rows of data.\n\n- `engine.print_table(tb_name)` : It prints the table in pretty format for you to see.\n\n- `engine.clear_table(tb_name)` : It removes all the data from the table with provided table name\n\n- `engine.close()` : It closes the connection to the database. If not called, the connection will be closed when `engine` object is destroyed.\n\n# Schema Functions to specify datatypes\n\n### How to Describe Schema\n> Schema can be describe by using the provided functions which are documented below:\n\n1. `Int` - means \"INT\" of SQL.\n\n2. `Float` - means \"Float\" of SQL. Doesnt support size and pricision as recommended by the Mysql docs.\n\n3. `Char` - means \"CHAR\" of SQL. By default of size 255.\n\n4. `VarChar` - means \"VARCHAR\" of SQL. By default of size 255 # does not take size like in SQL.\n\n### Equivalent to SQL counterparts\n`Date`, `DateTime`, `Time`, `Timestamp`\n\n# How Data is Generated\nThis module is designed such that the below provided hooks actually are mapped to functions which are responsible for data generation.\n\nBelow are the Hooks which can be used to generate data automatically, also Custom Generator functions can be provided which will then be called to generate data.\n\n\n### Hooks for Int / Float type data\n`random_int` : generates random integers - provide range with arguments\n```python\n# schema description\ntb_name = {\n  'age':Int(hook='random_int', args=(10,50))\n}\n```\n\n`random_digit` : generates random 0-9 digit.\n\n`random_float` : generates random float value in the range given in args.\n\n```python\nschema = {\n  'id':Float(hook='random_float', args=(50,200))\n}\n```\n\n`sequence` : generates sequenctial numbers from the range given using `args`.\n\n```python\nschema = {\n  'id':Int(hook='sequence', args=(50,100))\n}\n```\n\n`random_choice` : Randomly chooses values from a given list\n```python\nschema = {\n  'stream':VarChar(hook='random_choice', args=(['bca', 'btech', 'commerce', 'mtech']))\n}\n```\n\n### Hooks for VarChar / Char type data\n`name` : generates full names\n\n`first_name` : generates first names\n\n`email` : generates emails\n\n`last_name` : generates last names\n\n`address` : generates fake addresses\n\n`male_name` : generates male names\n\n`female_name` : generates female names\n\n`job`: generates a job name\n\n`phone_number` : generates phone numbers\n\n`md5` : Generates fake md5 hashes\n\n`sha1` : Generates sha1 hashes\n\n`uuid` : Generates UUID's\n\n\n### Hooks for Date/DateTime/Time/Timestamp type data\n\n`future_datetime` : generates a future datetime\n\n`past_datetime` : generates a past datetime\n\n`future_date`: generates a future date\n\n`past_date` : generates a past date\n\n`time` : generates time value HH:MM:SS\n\n`date`: generates date value\n\n`date_of_birth` : generates dob's in YYYY-MM-DD format\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Fill your database Quickly with dummy data",
    "version": "1.1.0",
    "split_keywords": [
        "sql",
        "sql dummy data",
        "fake data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd8f857d392c2b4a168db656e2c26ee02327a6aacbc5d7b69dd399dbca59e3fe",
                "md5": "12e92c5e19a66c3595cf813a04990c01",
                "sha256": "8d0267c14c5e8f66038b6177963fce8650feaccda08a870834327f2956bfb6cb"
            },
            "downloads": -1,
            "filename": "sqlsy-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "12e92c5e19a66c3595cf813a04990c01",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8175,
            "upload_time": "2023-04-27T14:16:24",
            "upload_time_iso_8601": "2023-04-27T14:16:24.521420Z",
            "url": "https://files.pythonhosted.org/packages/bd/8f/857d392c2b4a168db656e2c26ee02327a6aacbc5d7b69dd399dbca59e3fe/sqlsy-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "575720c35bf9deccb059364064571ee881cc4c967092a761db3b9cad8970e3e7",
                "md5": "f159f43e39387419afc709bd68728b2b",
                "sha256": "4d59efe5c5e5cadd23b6aed614f47a91100610230976654ac60224ebf9760657"
            },
            "downloads": -1,
            "filename": "sqlsy-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f159f43e39387419afc709bd68728b2b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9246,
            "upload_time": "2023-04-27T14:16:27",
            "upload_time_iso_8601": "2023-04-27T14:16:27.777172Z",
            "url": "https://files.pythonhosted.org/packages/57/57/20c35bf9deccb059364064571ee881cc4c967092a761db3b9cad8970e3e7/sqlsy-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-27 14:16:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "sqlsy"
}
        
Elapsed time: 0.56256s