@@ -34,57 +34,49 @@ A few examples of the most common functionalities provided by the adapter:
34
34
``` python3
35
35
import polypheny
36
36
37
- # Connect to Polypheny
38
- connection = polypheny.connect(' 127.0.0.1 ' , 20590 , username = ' pa ' , password = ' ' , transport = ' plain ' )
37
+ # Connect to locally running Polypheny via UNIX sockets (on Linux, BSD and macOS)
38
+ con = polypheny.connect()
39
39
40
- # If Python 3.8 is used the connection needs to bespecified as a tuple. Uncomment the following line
41
- # connection = polypheny.connect(('127.0.0.1', 20590), username='pa', password='', transport='plain')
40
+ # Unencrypted over the network (all systems)
41
+ con = polypheny.connect(
42
+ (' 127.0.0.1' , 20590 ),
43
+ username = ' pa' ,
44
+ password = ' ' ,
45
+ transport = ' plain' ,
46
+ )
42
47
43
48
# Get a cursor
44
- cursor = connection .cursor()
49
+ cursor = con .cursor()
45
50
46
51
# Create a new table
47
52
cursor.execute(" CREATE TABLE dummy (id INT NOT NULL, text VARCHAR(2), num INT, PRIMARY KEY(id))" )
48
53
49
54
# Insert values into table
50
55
cursor.execute(" INSERT INTO dummy VALUES (407 , 'de', 93)" )
51
- connection .commit()
56
+ con .commit()
52
57
53
58
# Execute a query
54
59
cursor.execute(" SELECT * from dummy" )
55
60
56
- print (" \n Relational output from SQL" )
57
- print (" \t " ,cursor.fetchone())
61
+ print (" \n Relational results from SQL" )
62
+ for row in cursor:
63
+ print (" \t " , row)
58
64
59
65
# Accessing data using MQL
60
- cursor.executeany(' mongo' , ' db.dummy.find()' ,namespace = ' public' )
61
-
62
- return_mql = cursor.fetchone()
63
- # json_output = json.loads( return_mql )
64
-
65
-
66
- print (" \n Plain JSON output from MQL" )
67
- print (" \t " ,return_mql)
68
-
69
-
70
-
71
- print (" \n Plain JSON key 'text' from from MQL return" )
72
- print (" \t " ,return_mql[" text" ])
66
+ cursor.executeany(' mongo' , ' db.dummy.find()' , namespace = ' public' )
73
67
68
+ print (" \n Document results from MQL (as Python dicts)" )
69
+ for doc in cursor:
70
+ print (" \t " , doc)
74
71
75
72
cursor.execute(" DROP TABLE dummy" )
76
73
77
- # Print result
78
- # for f in cursor:
79
- # print(f)
80
-
81
74
# Close the connection
82
- connection .close()
75
+ con .close()
83
76
```
84
77
85
78
An in-depth and more detailed documentation can be found [ here] ( https://docs.polypheny.com/en/latest/drivers/python/overview ) .
86
79
87
-
88
80
## Tests
89
81
Run the tests with coverage report:
90
82
```
0 commit comments