Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
segasai authored Feb 14, 2024
1 parent 7e65009 commit 380a0c2
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# sqlutilpy
Python module to query SQL databases and return numpy arrays, upload
tables and run join queries involving local arrays and the tables in the DB.
The module only works with PostgreSQL and SQLite databases.
This module is optimized to be able to deal efficiently with query results with millions of rows.
The module only works PostgreSQL, SQLite and duckdb databases.

The full documentation is available [here](http://sqlutilpy.readthedocs.io/en/latest/)

Expand All @@ -18,10 +19,11 @@ To install the package you just need to do pip install.
```
pip install sqlutilpy
```
## Authentification
Throughout this readme, I'll assume that the .pgpass file ( https://www.postgresql.org/docs/11/libpq-pgpass.html )
has been created with the login/password details for Postgresql. If that is not the case, all of the
commands given above will also need user='....' and password='...' options
## Authentication

Throughout this readme, I will assume that the .pgpass file ( https://www.postgresql.org/docs/11/libpq-pgpass.html )
has been created with your login/password details for Postgresql. If that is not the case, all of the
commands given below will also need user='....' and password='...' options

## Connection information

Expand All @@ -32,17 +34,20 @@ of the connection.


## Querying the database and retrieving the results

This command will run the query and put the columns into variables ra,dec
```python
import sqlutilpy
ra,dec = squtilpy.get('select ra,dec from mytable',
host='HOST_NAME_OF_MY_PG_SERVER',
db='THE_NAME_OF_MY_DB')
```

By default sqlutilpy.get executes the result and returns the tuple of
results. But you can return the results as dictionary using asDict option.
By default sqlutilpy.get executes the query and returns the tuple with
results. You can return the results as dictionary using asDict option.

## Uploading your arrays as column in a table

```python
x = np.arange(10)
y = x**.5
Expand All @@ -60,18 +65,21 @@ you could upload the arrays in the DB and run a query, but local_join function d
myid = np.arange(10)
y = x**.5
R=sqlutilpy.local_join('''select * from mytmptable as m,
somebigtable as s where s.id=m.myid order by m.myid''', 'mytmptable',(x,y),('myid','ycol'))
somebigtable as s where s.id=m.myid order by m.myid''',
'mytmptable',(x,y),('myid','ycol'))
```
It executes a query as if you arrays where in a mytmptable. ( behind the scenes
it uploads the data to the db and runs a query)

It executes a query as if you arrays were in mytmptable. (behind the scenes
it uploads the data to the db and runs a query)

## Keeping the connection open.

Often it's benefitial to preserve an open connection. You can do that if you first
Often it is beneficial to preserve an open connection to the database. You can do that if you first
obtain the connection using sqlutilpy.getConnection() and then provide it directly
to sqlutil.get() and friends using conn=conn argument


# How to cite it
If you use this, please cite it through zenodo https://doi.org/10.5281/zenodo.6867957
# How to cite the software

If you use this package, please cite it through zenodo https://doi.org/10.5281/zenodo.6867957

0 comments on commit 380a0c2

Please sign in to comment.