|
3 | 3 |
|
4 | 4 | con = mindsdb_sdk.connect() |
5 | 5 |
|
6 | | -# get user's database (connected to mindsdb as rental_db) |
7 | | -db = con.databases.rental_db |
| 6 | +# connect to mindsdb example database |
| 7 | +example_db = con.databases.create( |
| 8 | + 'example_db', |
| 9 | + engine='postgres', |
| 10 | + connection_args={ |
| 11 | + "user": "demo_user", |
| 12 | + "password": "demo_password", |
| 13 | + "host": "3.220.66.106", |
| 14 | + "port": "5432", |
| 15 | + "database": "demo" |
| 16 | + } |
| 17 | +) |
8 | 18 |
|
9 | | -# get table |
10 | | -table1 = db.tables.house_sales |
| 19 | +# connect to the empty user database |
| 20 | +my_db = con.databases.create( |
| 21 | + 'my_db', |
| 22 | + engine='postgres', |
| 23 | + connection_args={ |
| 24 | + "user": "postgres", |
| 25 | + "host": "localhost", |
| 26 | + "port": "5432", |
| 27 | + "database": "my_database" |
| 28 | + } |
| 29 | +) |
11 | 30 |
|
| 31 | +# get home_rentals table |
| 32 | +table1 = example_db.tables.get('demo_data.home_rentals') |
12 | 33 |
|
13 | 34 | # ---- create new table ---- |
14 | 35 |
|
15 | | -# copy create table house_sales and fill it with rows with type=house |
16 | | -table2 = db.tables.create('house_sales2', table1.filter(type='house')) |
| 36 | +# create table home_rentals in user db and fill it with rows with location=great |
| 37 | +table2 = my_db.tables.create('home_rentals', table1.filter(location='great')) |
| 38 | + |
17 | 39 |
|
18 | 40 | # create table from csv file |
| 41 | + |
19 | 42 | df = pd.read_csv('my_data.csv') |
20 | | -table3 = db.tables.create('my_table', df) |
| 43 | +table3 = my_db.tables.create('my_table', df) |
21 | 44 |
|
22 | 45 |
|
23 | 46 | # ---- insert into table ---- |
|
28 | 51 |
|
29 | 52 | # ---- update data in table ---- |
30 | 53 |
|
31 | | -# get all rows with type=house from table1 and update values in table2 using key ('saledate', 'type', 'bedrooms') |
| 54 | +# get all rows with number_of_rooms=1 from table1 and update values in table2 using key ('location', 'neighborhood') |
32 | 55 | table2.update( |
33 | | - table1.filter(type='house'), |
34 | | - on=['saledate', 'type', 'bedrooms'] |
| 56 | + table1.filter(number_of_rooms=1), |
| 57 | + on=['location', 'neighborhood'] |
35 | 58 | ) |
36 | 59 |
|
37 | 60 |
|
38 | 61 | # ---- delete rows from table ---- |
39 | 62 |
|
40 | 63 | # delete all rows where bedrooms=2 |
41 | | -table2.delete(bedrooms=2) |
| 64 | +table2.delete(number_of_rooms=1) |
42 | 65 |
|
43 | 66 |
|
0 commit comments