# TinyDB
**Repository Path**: gitee-tyx/tiny-db
## Basic Information
- **Project Name**: TinyDB
- **Description**: 基于IPFS和Hyperledger Fabric的物联网数据存储平台
- **Primary Language**: Python
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2023-10-18
- **Last Updated**: 2024-04-17
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# README
## 0. Preparation
**pre-installation requirements:**
1. [Docker](https://docs.docker.com/install/)
2. Git
3. [Hyperledger Fabric 2.5.4 (TestNet)](https://hyperledger-fabric.readthedocs.io/en/latest/install.html#download-fabric-samples-docker-images-and-binaries)
```bash
# You can follow this to build a Hyperledger Fabric testnet 2.5.4
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/bootstrap.sh| bash -s
./install-fabric.sh docker samples binary
./install-fabric.sh --fabric-version 2.5.4 binary
```
4. [Go 1.19.x](https://golang.org/doc/install)
5. [Kubo 0.22.0 (IPFS)](https://docs.ipfs.tech/install/command-line#install-official-binary-distributions)
```bash
# 下面是以linux-amd64为例的安装过程
wget https://dist.ipfs.tech/kubo/v0.22.0/kubo_v0.22.0_linux-amd64.tar.gz
tar -xvzf kubo_v0.22.0_linux-amd64.tar.gz
> x kubo/install.sh
> x kubo/ipfs
> x kubo/LICENSE
> x kubo/LICENSE-APACHE
> x kubo/LICENSE-MIT
> x kubo/README.md
cd kubo
sudo bash install.sh
> Moved ./ipfs to /usr/local/bin
ipfs --version
> ipfs version 0.22.0
```
6. Python >= 3.7
7. Python Requirements
7.1 RabbitMQ
```bash
pip install pika
```
7.2 [Kubo RPC API](https://docs.ipfs.tech/reference/kubo/rpc/#getting-started)
7.3 fabric-sdk-py
```bash
$ git clone https://github.com/hyperledger/fabric-sdk-py.git
$ cd fabric-sdk-py
$ make install
```
**Pull project repository:**
```
mkdir ~/tiny-db
cd ~/tiny-db
git clone https://gitee.com/gitee-tyx/tiny-db.git
```
## 1. Framework
tiny-db/
├── main # Main files of TinyDB.
│ ├── tinydb_client.py # You can use the function in this file to interact with TinyDB.
│ └── tinydb_server.py # The core logic of TinyDB.
└── test_cases # Some test case used by developers.
## 2. Usage
### 2.1 Add
```python
from tinydb_client.py import TinyDBClient
hash = TinyDBClinet.send_data(data, time)
# input: data->需要存储的数据,我们假设用户在发送前已经完成加密,类型为string
# input: time->数据生成的时间,类型为时间戳(float)
# output:hash->content的哈希值hash,类型为string
```
### 2.2 Query
```python
from tinydb_client.py import TinyDBClient
content = TinyDBClinet.query_data(hash)
# input: hash->根据哈希值查找内容,hash类型为stirng
# output:content->解密后的文件内容,类型为string
```