feat: adding database module

This commit is contained in:
Mose Mueller
2023-06-05 15:55:19 +02:00
parent fc4b351248
commit 58814204e9
6 changed files with 751 additions and 117 deletions

View File

@@ -2,8 +2,22 @@
ICON Service Base is a git repository that contains code shared among all Icon services in a service-oriented architecture. The repository consists of a backend written in Python and a frontend written in TypeScript.
## Modules
### Database Module
The Database module provides a robust and scalable solution for interacting with our PostgreSQL and InfluxDB databases.
#### PostgreSQL
The PostgreSQL section includes a class for managing PostgreSQL database sessions (`PostgresDatabaseSession`). It provides a Pythonic interface to the SQL language using the `sqlmodel` library, and includes features for managing transactions and handling errors.
#### InfluxDB
The InfluxDB section provides a class (`InfluxDBConnection`) to manage connections to an InfluxDB server. This connection is established using credentials provided through environment variables. The class serves as a context manager to handle these connections, automatically opening and closing the connection when needed. It provides functionalities for writing data points to a bucket and creating new buckets.
## Installation
### Python
Make sure you have Python 3.10 or later installed on your system. The dependencies of this package are handled with [`poetry`](https://python-poetry.org/docs/#installation). You can install the `icon_service_base` like so:
@@ -13,6 +27,7 @@ poetry add git+ssh://git@gitlab.phys.ethz.ch:tiqi-projects/qchub/icon-services/i
```
### TypeScript frontend
Make sure you have Node.js and npm or yarn installed on your system. You can install `@icon-services/icon_service_base` like so:
```bash
@@ -20,19 +35,26 @@ npm install git+ssh://git@gitlab.phys.ethz.ch:tiqi-projects/qchub/icon-services/
```
## Usage
### Python
The Python code can be used as a library in other ICON services. Import the relevant modules and classes from the `icon_service_base` package in your Python code, as needed.
### TypeScript Frontend
The frontend code contains the core of the typescript openAPI clients generated by [`openapi-typescript-codegen`](https://github.com/ferdikoomen/openapi-typescript-codegen/tree/master). This needs to be imported in the ICON services like so:
```ts
import { OpenAPI } from '@icon-services/icon_service_base';
import { request as __request } from '@icon-services/icon_service_base';
export { ApiError } from "@icon-services/icon_service_base";
export { CancelablePromise, CancelError } from '@icon-services/icon_service_base';
export type { OpenAPIConfig } from '@icon-services/icon_service_base';
import { OpenAPI } from '@icon-services/icon_service_base'
import { request as __request } from '@icon-services/icon_service_base'
export { ApiError } from '@icon-services/icon_service_base'
export {
CancelablePromise,
CancelError,
} from '@icon-services/icon_service_base'
export type { OpenAPIConfig } from '@icon-services/icon_service_base'
```
## License
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.