Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
# Aloha!

## What is it?

`aloha` is a versatile Python utility package for building microservices.

[![License](https://img.shields.io/github/license/QPod/aloha)](https://github.com/QPod/aloha/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/QPod/aloha-python/pip.yml?branch=main)](https://github.com/QPod/aloha-python/actions)
[![Join the Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/QPod/)
[![PyPI version](https://img.shields.io/pypi/v/aloha)](https://pypi.python.org/pypi/aloha/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/aloha)](https://pepy.tech/badge/aloha/)
[![Code Activity](https://img.shields.io/github/commit-activity/m/QPod/aloha)](https://github.com/QPod/aloha/pulse)
[![Recent Code Update](https://img.shields.io/github/last-commit/QPod/docker-images.svg)](https://github.com/QPod/aloha/stargazers)

Please generously STAR★ our project or donate to us! [![GitHub Starts](https://img.shields.io/github/stars/QPod/aloha.svg?label=Stars&style=social)](https://github.com/QPod/aloha/stargazers)
[![PyPI version](https://img.shields.io/pypi/v/aloha)](https://pypi.python.org/pypi/aloha/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/aloha)](https://pepy.tech/badge/aloha/)

---

Please generously STAR★ our project or donate to us!
[![GitHub Starts](https://img.shields.io/github/stars/QPod/aloha.svg?label=Stars&style=social)](https://github.com/QPod/aloha/stargazers)
[![Donate-PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/haobibo)
[![Donate-AliPay](https://img.shields.io/badge/Donate-Alipay-blue.svg)](https://raw.githubusercontent.com/wiki/haobibo/resources/img/Donate-AliPay.png)
[![Donate-WeChat](https://img.shields.io/badge/Donate-WeChat-green.svg)](https://raw.githubusercontent.com/wiki/haobibo/resources/img/Donate-WeChat.png)

## What is it?

`aloha` is a versatile Python utility package for building microservices.
- For questions, try DeepWiki: [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/QPod/aloha-python)

[📚 Document & 中文文档](https://aloha-python.readthedocs.io/)
- To contribute or talk to a human: [![Open an Issue on GitHub](https://img.shields.io/github/issues/QPod/aloha-python)](https://github.com/QPod/aloha-python/issues) [![Join the Discord Chat](https://img.shields.io/badge/Discuss_on-Discord-green)](https://discord.gg/kHUzgQxgbJ)

## Getting started

Refer to[📚 Document & 中文文档](https://aloha-python.readthedocs.io/) for detailed introduction.

```shell
pip install aloha[all]
```

And then:
```python
from aloha.logger import LOG
from aloha.settings import SETTINGS as S
```
23 changes: 10 additions & 13 deletions src/aloha/db/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

class DuckOperator:
def __init__(self, db_config, **kwargs):
"""
db_config example:
"""db_config example:
{
"path": "/path/to/db.duckdb", # 数据库文件路径,使用 ":memory:" 表示内存模式
"schema": "sales", # 可选,默认 'main'
"read_only": True, # 可选,默认 False (内存模式下强制为 False)
"config": {"memory_limit": "500mb"}# 可选,DuckDB 连接配置
"path": "/path/to/db.duckdb", # file path of duckdb, use ":memory:" for in-memory mode
"schema": "sales", # optional, 'main' by default
"read_only": True, # optional, False by default, (will set to False if in in-memory mode)
"config": {"memory_limit": "500mb"}, # optional, duckdb connection configs
}
"""
self._config = {
Expand All @@ -28,10 +27,10 @@ def __init__(self, db_config, **kwargs):
'config': db_config.get('config', {}),
}

if not self._config['path'] or self._config['path'] == ':memory:': # 标准化内存模式路径
if not self._config['path'] or self._config['path'] == ':memory:': # in-memroy mode
self._config['path'] = ':memory:'

if self._config['read_only']: # 内存数据库不支持只读模式
if self._config['read_only']: # in-memory mode cannot be read-only
LOG.warning("In-memory database cannot be read-only. Setting read_only=False.")
self._config['read_only'] = False

Expand All @@ -50,16 +49,14 @@ def __init__(self, db_config, **kwargs):
).connect()

self._initialize_schema()

LOG.debug(
f"DuckDB connected: {self._config['path']} [schema={self._config['schema']}, read_only={self._config['read_only']}]"
)
msg = f"DuckDB connected: {self._config['path']} [schema={self._config['schema']}, read_only={self._config['read_only']}]"
LOG.debug(msg)
except Exception as e:
LOG.exception(e)
raise RuntimeError('Failed to connect to DuckDB')

def _prepare_database(self):
"""准备数据库文件和目录"""
"""Prepare the database file and its parent directory."""
path = self._config['path']
path_obj = Path(path)

Expand Down