How to install
pip install db2ls
git clone https://github.com/Jianfengliu0413/db2ls.git
usage:
from db2ls import db2ls
db path
# Example usage
db_path = 'test.db'
connect
# option 1: dirrect connect
db2ls.connect(db_path)
<db2ls.db2ls.db2ls at 0x1110ff5c0>
db2ls.connect(db_path).vacuum()
Error executing query: no such table: change_log
Database vacuumed
create a table
table="germany"
# option 2: use "with" method
with db2ls(db_path) as db:
db.create(table,["id integer primary key", "city text", "postcode text"])
Error executing query: no such table: change_log
Table created with definition: CREATE TABLE IF NOT EXISTS germany (id integer primary key, city text, postcode text)
Connection closed
insert info
with db2ls(db_path) as db:
db.insert(table, ['id', 'city',"postcode"], [1,"Heidelberg","69115"])
Error executing query: no such table: change_log
Data inserted into germany: [1, 'Heidelberg', '69115']
Connection closed
take a look
with db2ls(db_path) as db:
db.print(table, ['id', 'city',"postcode"])
(1, 'Heidelberg', '69115')
Connection closed
only check specific columns
with db2ls(db_path) as db:
db.print(table, ['id', 'city'])
(1, 'Heidelberg')
Connection closed
or check all (*)
with db2ls(db_path) as db:
db.print(table, ["*"])
db.print(table, "*") # not work
(1, 'Heidelberg', '69115')
(1, 'Heidelberg', '69115')
Connection closed
insert more data
with db2ls(db_path) as db:
db.insert(table, ['id', 'city',"postcode"], [2,"Neckargemuend","69151"])
db.insert(table, ['id', 'city',"postcode"], [3,"Wiesloch","69168"])
db.insert(table, ['id', 'city',"postcode"], [4,"Leimen","69181"])
db.insert(table, ['id', 'city',"postcode"], [5,"Walldorf","69190"])
db.insert(table, ['id', 'city',"postcode"], [6,"Schriesheim","69198"])
db.insert(table, ['id', 'city',"postcode"], [7,"Sandhausen","69207"])
Error executing query: no such table: change_log
Data inserted into germany: [2, 'Neckargemuend', '69151']
Error executing query: no such table: change_log
Data inserted into germany: [3, 'Wiesloch', '69168']
Error executing query: no such table: change_log
Data inserted into germany: [4, 'Leimen', '69181']
Error executing query: no such table: change_log
Data inserted into germany: [5, 'Walldorf', '69190']
Error executing query: no such table: change_log
Data inserted into germany: [6, 'Schriesheim', '69198']
Error executing query: no such table: change_log
Data inserted into germany: [7, 'Sandhausen', '69207']
Connection closed
with db2ls(db_path) as db:
db.print(table, ["*"])
(1, 'Heidelberg', '69115')
(2, 'Neckargemuend', '69151')
(3, 'Wiesloch', '69168')
(4, 'Leimen', '69181')
(5, 'Walldorf', '69190')
Connection closed
you see: only first 5 get printed
with db2ls(db_path) as db:
db.print(table, "*",n=10)
(1, 'Heidelberg', '69115')
(2, 'Neckargemuend', '69151')
(3, 'Wiesloch', '69168')
(4, 'Leimen', '69181')
(5, 'Walldorf', '69190')
(6, 'Schriesheim', '69198')
(7, 'Sandhausen', '69207')
Connection closed
update table
if i want to change the postcode in city 'Leimen'
db.connect(db_path).execute("update germany set city='Tübingen' where city = 'Leimen'")
db.connect(db_path).print("germany")
Error executing query: no such table: change_log
(1, 'Heidelberg', '69115')
(2, 'Neckargemuend', '69151')
(3, 'Wiesloch', '69168')
(4, 'Tübingen', '69181')
(5, 'Walldorf', '69190')
with db2ls(db_path) as db:
db.update(table, "postcode = '72076'", "postcode = '69181'")
db.print(table,"*")
UPDATE germany SET postcode = '72076' WHERE postcode = '69181'
Error executing query: no such table: change_log
(1, 'Heidelberg', '69115')
(2, 'Neckargemuend', '69151')
(3, 'Wiesloch', '69168')
(4, 'Tübingen', '72076')
(5, 'Walldorf', '69190')
Connection closed
get columns names
db.connect(db_path).columns(table)
['id', 'city', 'postcode']
conver to DataFrame()
db.connect(db_path).to_df(table)
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| id | city | postcode | |
|---|---|---|---|
| 0 | 1 | Heidelberg | 69115 |
| 1 | 2 | Neckargemuend | 69151 |
| 2 | 3 | Wiesloch | 69168 |
| 3 | 4 | Tübingen | 72076 |
| 4 | 5 | Walldorf | 69190 |
| 5 | 6 | Schriesheim | 69198 |
| 6 | 7 | Sandhausen | 69207 |
db.connect(db_path).to_df(table)["city"].tolist()
['Heidelberg',
'Neckargemuend',
'Wiesloch',
'Tübingen',
'Walldorf',
'Schriesheim',
'Sandhausen']
Metadata
Release files for db2ls 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| db2ls-0.1.3.tar.gz | 64.9 kB | Without provenance | Details for db2ls-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| db2ls-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for db2ls-0.1.3-py3-none-any.whl |
Total release size: 138.5 kB
Release files / db2ls-0.1.3.tar.gz
| Download URL | db2ls-0.1.3.tar.gz |
|---|---|
| Size | 64.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
038881cdceaf8978282ff51509fd4580e18c7cb37cec55fccd51d365ff98d0f7
|
|
BLAKE2b-256 checksum How to use checksums |
3dc78c4dc051ff4c6a9ec4d5c2b0810e0e54222e87d94ea82c9470c9f4daa6b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0
|
Release files / db2ls-0.1.3-py3-none-any.whl
| Download URL | db2ls-0.1.3-py3-none-any.whl |
|---|---|
| Size | 73.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3fa08f5eeab652e4379a58f81c0a1b785be5217645b818414344822082d77e59
|
|
BLAKE2b-256 checksum How to use checksums |
e53c72d0aa5404d08bd04f54f9ea921b4532088d88a07e533c95d8df52b65a66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0
|
Security for db2ls 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.