Metadata-Version: 2.1
Name: magicdb-cli
Version: 1.0.23
Summary: magicdb client cmd tool
Home-page: https://github.com/uopensail/magicdb-cli
Author: TimePi
Author-email: timepi@uopensail.com
License: License :: AGLP3
Keywords: magicdb client
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mmh3 ==3.0.0
Requires-Dist: pandas ==1.2.0
Requires-Dist: pyarrow ==6.0.1
Requires-Dist: antlr4-python3-runtime ==4.12
Requires-Dist: etcd3 ==0.12.0
Requires-Dist: awswrangler ==2.18.0
Requires-Dist: boto3 ==1.26.27

# Install 


```shell
pip install magicdb_cli
```

# Tutorials

## Database Operations

### List All Databases
```sql
show databases;
```

### Create A Database
```sql
-- db_name: the name of this database
create database [if not exists] db_name with properties ("k1"="v1", "k2"="v2");
```
properties `MUST CONTAIN` these keys:
1. bucket: bucket name of OSS/S3 example: (s3://bucket-name | oss://test-bucket)
2. endpoint: endpoint for OSS/S3
3. access_key: token for account
4. secret_key: token for account

### Delete A Database
```sql
drop database [if exists] db_name;
```

## Table Operations
### List All Tables Of A Database
```sql
-- db_name: the name of this database
show tables db_name;
```
### Drop A Table
```sql
-- db_name: the name of this database
drop table [if exists] db_name.table_name;
```

### Create A Table Of A Database
```sql
-- db_name: the name of this database
-- table_name: the name of this table
create table [if not exists] db_name.table_name with properties ("k1"="v1", "k2"="v2");
```
properties `MUST CONTAIN` these keys:
1. data: the path to put sqlite files
2. meta: the path to put meta files

### Show Table Info
```sql
-- db_name: the name of this database
-- table_name: the name of this table
desc db_name.table_name;
describe db_name.table_name;
```

## Versions Operations

### List All Versions Of A Table

```sql
-- db_name: the name of this database
-- table_name: the name of this table
show versions db_name.table_name;
```

### Show Current Version Of A Table

```sql
-- db_name: the name of this database
-- table_name: the name of this table
show current version db_name.table_name;
```

### Update Current Version Of A Table

```sql
-- db_name: the name of this database
-- table_name: the name of this table
-- version1: the name of current version
update table db_name.table_name set current version = "version1";
```

### Drop A Version Of A Table

```sql
-- db_name: the name of this database
-- table_name: the name of this table
-- version1: the name of current version

-- if `version1` is current version, then the new current version is set `nil`.
alter table db_name.table_name drop version("version1");
```


## Machine Operations

### List ALL Machines of A Database
```sql
-- db_name: the name of this database
show machines db_name;
```

### Delete A Machine Of A Database
```sql
-- db_name: the name of this database
-- machine_ip: ip of this machine
alter database db_name drop machine("machine_ip");
```

### Add A Machine Of A Database
```sql
-- db_name: the name of this database
-- machine_ip: ip of this machine
alter database db_name add machine("machine_ip");
```


## Load And Select Operations

### Load Data To A Table
```sql
-- db_name: the name of this database
-- table_name: the name of this table
-- properties are optional
-- path: hive table path

load data "path" into db_name.table_name [with with properties ("k1"="v1", "k2":"v2")];

```
properties `MUST CONTAIN` these keys:
1. key: primary key of table

properties `MAY CONTAIN` these keys:
1. partitions: partitions to split, default: 100
2. workdir: where to save the load data, defalue: /tmp/$db_name/$table_name/$timestamp/
3. workers: process num, default: max(cup()-1, 1)



### Select Data From Table
```sql
-- db_name: the name of this database
-- table_name: the name of this table
-- key: the primary key value
-- field: the primary key field

select * from db_name.table_name where field = 'key';
```
 
