Skip to content

Commit 229fe4d

Browse files
committed
Add LICENCE and README
1 parent 129b58a commit 229fe4d

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Nils T.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# sql-generator
2+
3+
This tool lets you generate postgresql insert statements for common data types.
4+
It's pretty minimalistic at the moment but offers support for basic statements
5+
and foreign key relations.
6+
7+
In addition to that, `sql-generator` supports custom generators for table columns
8+
and data types.
9+
10+
## Usage
11+
12+
```python
13+
from generator import Generator, write_results_to_file
14+
import psycopg2
15+
16+
# Custom converter for all columns or data types with
17+
# `custom_a` as name.
18+
def gen_column_a(column):
19+
return f"My data type is {column.data_type}!"
20+
21+
conn = psycopg2.connect("your dsn")
22+
gen = Generator(conn, custom_converters={"column_a": gen_column_a})
23+
# Amount of inserts per table.
24+
amounts = {"table_a": 50, "table_b": 25, "table_c": 100}
25+
generated_statements: dict = gen.generate_table_data_for_all(amounts)
26+
# Write generated statements to file.
27+
# You can optionally truncate your db with `should_truncate=True`.
28+
write_results_to_file(generated_statements, dest="your_output.sql")
29+
```

generators.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2020 Nils T.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
"""
24+
125
import random
226
import string
327
import time

0 commit comments

Comments
 (0)