Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
ts7ming committed May 25, 2024
1 parent 2fecd7b commit 3e3600c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/en/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ read and write databases and other datasource
- get_sql(sql) same as read_sql
- exe_sql(sql)
- to_db(df, tb_name[, how, fast_load, chunksize])
- df: pd.DataFrame()对象
- df: pd.DataFrame()
- tb_name: target table name
- how: option, default append,
- fast_load: option, default False; only support MySQL and Clickhouse, export pd.DataFrame to a temp csv then import to db
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pyqueen',
version='1.1.0',
version='1.1.1',
url='https://github.com/ts7ming/pyqueen.git',
description='Rule your Data',
long_description=open("README.md", encoding='utf-8').read(),
Expand Down
61 changes: 58 additions & 3 deletions test/test_data_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pandas as pd

from pyqueen import DataSource


Expand Down Expand Up @@ -28,6 +30,33 @@ def test_mysql():
else:
print('mysql read_sql not match')

def test_mysql2():
ds = DataSource(conn_type='mysql', host='olympus', username='root', password='54maqiming', port=3306, db_name='cdc_source')

sql = 'DROP TABLE IF EXISTS t_table'
ds.exe_sql(sql)

sql = '''
CREATE TABLE t_table (
id INT NOT NULL,
name varchar(100) NULL
)
'''
ds.exe_sql(sql)
print('mysql exe_sql is ok')

import pandas as pd

df = pd.DataFrame({'id': [1, 2, 3, 4], 'name': ['libnl', 'agds', 'gfrt', 'hhg']})
ds.to_db(df, tb_name='t_table', fast_load=False)
print('mysql to_db is ok')

v = ds.get_sql('select count(1) as v from t_table')
if int(v.values[0][0]) == 4:
print('mysql read_sql is ok')
else:
print('mysql read_sql not match')


def test_postgresql():
ds = DataSource(conn_type='pgsql', host='localhost', username='postgres', password='1qaz2wsx!', port=5432, db_name='postgres')
Expand Down Expand Up @@ -74,7 +103,33 @@ def test_redis():
print('redis get not match')


def test_sqlite():
ds = DataSource(conn_type='sqlite', file_path='tst.db')
import pandas as pd

df = pd.DataFrame({'dd': [1, 2, 3], 'gg': ['daf', 'gfytr', 'eee']})
ds.to_db(df, tb_name='hhhhh')
print('sqlite: to_db is ok')
sql = 'select max(dd) as f from hhhhh'
v = int(ds.get_value(sql))
if v == 3:
print('sqlite: read_sql is ok')

def test_excel():
ds = DataSource(conn_type='excel', file_path='./tst.xlsx')
import pandas as pd

df = pd.DataFrame({'dd': [1, 2, 3], 'gg': ['daf', 'gfytr', 'eee']})
ds.to_excel(sheet_list=[[df,'ma']])
print('excel: to_excel is ok')




if __name__ == '__main__':
test_mysql()
test_postgresql()
test_redis()
# test_mysql()
test_mysql2()
# test_postgresql()
# test_redis()
test_sqlite()
test_excel()

0 comments on commit 3e3600c

Please sign in to comment.