snapaddy / databank Goto Github PK
View Code? Open in Web Editor NEWDatabank is an easy-to-use Python library for making raw SQL queries in a multi-threaded environment.
License: MIT License
Databank is an easy-to-use Python library for making raw SQL queries in a multi-threaded environment.
License: MIT License
That you can run queries in parallel without worrying about async
/await
:
db = Database()
db.execute_many(query, batch_size=5)
which will process 5 queries in parallel.
And also something like:
db.execute(query, await=False)
if you do not want the process to be blocked.
Implement a "dry run" method to print the SQL query to be executed with escaped parameters etc.
.env/lib/python3.10/site-packages/databank/core.py:162: RemovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings. Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
When I want to insert into a table with execute_many()
I can use multiple params. But sometimes it is possible that values of a dictionary contain empty strings which can't be inserted. The solution is to change them to None
.
insert_queries = QueryCollection.from_file("src/queries/insert.sql")
album_params = [{
"artist_name": "HVOB",
"album_name": "HVOB",
"album_release_date": "",
"album_type": "Album",
"album_genre": ""
},]
db.execute_many(insert_queries["insert_album"], album_params)
My question is: Is there maybe a solution planned to automatically convert empty strings to None
or is the expected solution here to convert the empty strings to None
by the user?
I would like to execute all queries of my QueryCollection
like in the following example:
create_queries = QueryCollection.from_file("src/queries/create.sql")
for _, query in create_queries._queries.items():
db.execute(query)
Does _queries
has to be private? If not, one could access it directly (although it is obviously also now possible to do this, but not recommend because it is private ๐ ) and looping over it.
Alternatively, one could add the following getter function:
def get_queries(self):
return self._queries
If a .sql
file has more than one newline between each statement, one gets the following error:
databank.query.InvalidQueryHeader: '' is not a valid query header
/* @name create_album */
CREATE TABLE IF NOT EXISTS album (
...
);
/* @name create_review */
CREATE TABLE IF NOT EXISTS review (
...
);
.sql
files.sql
file before further processingUsing fetch_all()
with a JOIN
in the query, resulting in a result containing the same column name twice, shows only one of both resulting columns in output dictionary.
Example:
Two tables contain a column called name
.
We join both tables and the result table now has two columns called name
.
With fetch_all()
we only get one result set for a column called name
(dictionary has unique keys).
Possible fixes:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.