2019-06-17 21:29:45 +03:00
|
|
|
# ipython-cosmos-extension
|
|
|
|
IPython Extension for Cosmos SQL
|
|
|
|
|
|
|
|
## Install the extension:
|
|
|
|
```bash
|
2019-06-19 23:12:02 +03:00
|
|
|
!pip install ipython-cosmos-extension
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
|
|
|
## Load the extension:
|
|
|
|
This extension assumes cosmosdb endpoint credentials
|
|
|
|
are set as environment variables accessible by
|
|
|
|
``COSMOS_ENDPOINT`` and ``COSMOS_KEY``.
|
|
|
|
```bash
|
2019-06-19 23:12:02 +03:00
|
|
|
%load_ext cosmos_sql
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
|
|
|
## Set Database name
|
|
|
|
```bash
|
2019-06-19 23:12:02 +03:00
|
|
|
%database <your_database_name>
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
|
|
|
## Set Container name
|
|
|
|
```bash
|
2019-06-19 23:32:39 +03:00
|
|
|
%container <your_container_name>
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
|
|
|
## Execute Cosmos SQL Statements
|
|
|
|
```bash
|
2019-06-19 23:12:02 +03:00
|
|
|
%%sql
|
|
|
|
select * from user
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
2019-06-19 23:12:02 +03:00
|
|
|
or you can specify different database or collection
|
|
|
|
|
|
|
|
```bash
|
|
|
|
%%sql --database testdb --container testcol2
|
|
|
|
SELECT top 1 r.id, r._ts from r order by r._ts desc
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2019-06-17 21:29:45 +03:00
|
|
|
To get the result from the command use ``_`` variable.
|
|
|
|
## Auto conversion of result to data frame
|
|
|
|
Disabling auto conversion of result to dataframe:
|
|
|
|
```bash
|
2019-06-19 23:12:02 +03:00
|
|
|
%disable_autoconvert_to_dataframe
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
|
|
|
Enabling auto conversion of result to dataframe:
|
|
|
|
```bash
|
2019-06-19 23:12:02 +03:00
|
|
|
%enable_autoconvert_to_dataframe
|
2019-06-17 21:29:45 +03:00
|
|
|
```
|
|
|
|
|
2019-06-17 21:22:56 +03:00
|
|
|
|
|
|
|
# Contributing
|
|
|
|
|
|
|
|
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
|
|
|
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
|
|
|
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
|
|
|
|
|
|
|
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
|
|
|
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
|
|
|
provided by the bot. You will only need to do this once across all repos using our CLA.
|
|
|
|
|
|
|
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
|
|
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
|
|
|
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|