-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADMEmd
More file actions
148 lines (107 loc) · 4.55 KB
/
READMEmd
File metadata and controls
148 lines (107 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# db-engine
A lightweight, Bash-based database engine that uses directories and CSV files to emulate basic database functionalities. This project allows you to create databases, tables, schemas, and manage data right from your shell—no dependencies required beyond Bash and basic Unix utilities.
## Features
- **Create Database:** Make a new directory as your database.
- **Create Table:** Create CSV files as tables inside your database.
- **Define Schema:** Setup schemas (column definitions, types, constraints) for tables.
- **Link Schema to Table:** Metadata linking schemas to tables.
- **Add Constraints:** Specify required, optional, and unique columns.
- **Insert Rows:** Add new rows with auto-generated IDs, respecting schema constraints.
- **Select Rows:** Search for rows based on column criteria.
## How It Works
All commands are Bash functions defined in `main.sh`. To use them, source the file in your shell:
```bash
source main.sh
```
## Commands
### Create Database
```bash
mostafa-db create db <database-name>
```
Creates a new directory as your database.
### Create Table
```bash
table.create <db-name> create <table-name>
```
Creates a new CSV file (table) in your database.
### Define Schema
```bash
schema.create <schema-name> <db-name>
```
Creates a schema CSV file to define columns and constraints.
### Link Schema to Table
```bash
schema.link <schema-name> <table-name> <db-name>
```
Links a schema to a table, storing metadata in the table's file.
### Add Constraints to Schema
```bash
schema.constrains <schema-name> <db-name> "[col-name, data-type, required|optional, unique]"
```
Adds columns and constraints to a schema. You can add multiple constraints at once.
**Example:**
```bash
schema.constrains my-schema my-db "[name, string, required, unique]" "[age, int, optional]"
```
### Insert Row Into Table
```bash
table.insert <table-name> <db-name> {col_name: col_data, ...}
```
Inserts a new row, automatically generates an `id`, and checks constraints.
**Example:**
```bash
table.insert users my-db "{name: 'John Doe', age: 30, email: 'john@example.com'}"
```
### Select Rows
```bash
table.select <table-name> <db-name> {col_name: col_data, ...}
```
Selects rows matching criteria.
**Example:**
```bash
table.select users my-db "{email: 'john@example.com'}"
```
## Notes
- All data is stored locally using directories and CSV files.
- Schema constraints: `required`, `optional` (default is optional), `unique` (default is not unique).
- The `id` column is auto-generated and cannot be manually inserted.
- To use the functions, always source `main.sh` in your shell session.
## Example Workflow
```bash
source main.sh
mostafa-db create db my_db
table.create my_db create users
schema.create user_schema my_db
schema.constrains user_schema my_db "[name, string, required, unique]" "[email, string, required, unique]" "[age, int, optional]"
schema.link user_schema users my_db
table.insert users my_db "{name: 'Alice', email: 'alice@example.com', age: 25}"
table.select users my_db "{email: 'alice@example.com'}"
```
## Limitations & TODOs
- Only basic insert/select functionality provided. Delete/update not yet implemented.
- No support for complex queries.
- All data and schema definitions are stored as plain files; not suitable for production.
## Project Status
### ✅ What’s Done
- **Database Creation:** You can create a new database (directory).
- **Table Creation:** You can create new tables (CSV files) within a database.
- **Schema Creation:** You can define schemas specifying columns, types, and constraints.
- **Schema Linking:** You can link schemas to tables, storing column metadata.
- **Schema Constraints:** You can add required and unique constraints to schema columns.
- **Row Insertion:** You can insert new rows into tables, with auto-generated IDs and schema validation.
- **Row Selection:** You can select/search for rows in tables using column criteria.
### 🛠️ What’s To Be Done
- **Row Deletion:** Ability to delete rows from tables.
- **Row Update:** Ability to update/modify existing row data.
- **Advanced Querying:** Support for more complex queries and search functionalities.
- **Data Validation:** Enhanced validation for data types and formats.
- **Error Handling:** Improved error messages and robustness.
- **Backup/Restore:** Utilities for data backup and restoration.
- **Concurrency:** Handling simultaneous operations safely.
- **Documentation:** More examples and detailed usage guides.
---
Feel free to open issues or contribute to any of the above!
## Author
Mostafa Kadry
---
Feel free to contribute or suggest improvements!