Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Query builder based on psycopg2 to make querying databases in python more accessible for every day use
The goal of easypg is to allow others to easily use psycopg in a programmatic way and simplify creating scalable database queries within your python scripts.
Currently it is only possible to use simple connections via usernames and passwords to connect to local databases.
Essentially you just need to call dbActions('dbname', 'username') if there is a password you can enter it, but if not, the default is None so it is not required
By default easypg will use Psycopg's built-in dictionary cursor ('RealDictCursor') meaning that the output will be in a dictionary structure rather than the default output of psycopg. If you would like to change this you can simply pass the cursor_factory argument in the initialization of the database connection.
Possible values are:
operation('table', columns, arguments)
Here the columns part is either a list (for selects) or a dictionary of {columns:values} for inserts and updates.
The last argument allows users to pass any number of SQL key words as long as they are in the correct order for a normal SQL query and any spaces are replaced by an underscore.
Example:
The query "select column1, max(column2) from table where argument=value and arg2='test' group by column1" would look like:
dbActions.select('table', ['column1', 'max(column2)'], where='argument=value', and='arg2=test', group_by='column1') note: for SELECT actions only, the default value for columns is all so if no value is passed the result will be a 'select * ' statement.
The delete function has a slightly different syntax as specifying columns is not necessary. Still it follow a similar syntax to the other basic queries: delete('table', arguments)
Example:
To delete all elements of a table (test_table) where column2 is 'test' you would use delete("test_table", where="column2='test'")
Using common table expressions is very different from other queries as each one must first be assembled via the CTE function. They can then be included in the optional cte argument of the select function in order to be executed. For example, a cte, 'test' of "Select * from table1" must first be passed as cte('table1') style function. The CTE is extremely similar to a basic query in that the syntax of arguments is all the same, however the result is actually a preassembled SQL string that can be use in the final select query.
If the above example was set as a variable of "cte", it can then be used in a select function like so: select('table', cte={'test':cte}, limit=100)
The outcome of this would be the same as using the following query:
WITH 'test' as( SELECT * FROM table1) SELECT * FROM table LIMIT 100
Each element has a separate function with their own set of necessary arguments. For a database, only the name is required, but any extra that meet pg standards should be allowed in the same manner as other queries. Creating tables is different (hence the separate function) where you are required to include the name of the table and a dictionary with the names of the columns and a nested dictionary with a required 'type' element. You can also include a 'contraint' element in this dictionary if necessary.
Example: create_table('test', {'column1':{'type':'int', 'constraint':'unique'}, 'column2':{'type':'text'}})
Any of the pre-table name elements listed in the PG documentation can be included as *args elements after the columns dictionary.
As with basic query syntax, there is only a single function for dropping elements. This requires the 'obj' (ie TABLE/DATABASE etc) to be specified along with the name. Any other options can then be included as keyword arguments just as with basic query syntax.
FAQs
Query Builder to simplify working in postgres databases using Psycopg2
We found that ez-pg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.