diff --git a/src/databases/database.rs b/src/databases/database.rs
index 818e421..e29673d 100644
--- a/src/databases/database.rs
+++ b/src/databases/database.rs
@@ -18,14 +18,32 @@
use super::tables::table::Table;
-struct Database {
- tables: Vec
,
+#[derive(Debug)]
+pub struct Database {
+ pub name: String,
+ pub tables: Vec,
}
impl Database {
- pub fn new(tables: Vec) -> Self {
+ pub fn create_database(name: String) -> Self {
Self {
- tables
+ name,
+ tables: Vec::new(),
+ }
+ }
+
+ pub fn add_table(&mut self, name: String) {
+ self.tables.push(Table::create_table(name));
+ }
+
+ pub fn delete_table(&mut self, name: String) {
+ let mut ind = 0;
+ while ind != self.tables.len() {
+ if self.tables[ind].name == name {
+ self.tables.remove(ind);
+ } else {
+ ind += 1;
+ }
}
}
}
\ No newline at end of file
diff --git a/src/databases/tables/rows/row.rs b/src/databases/tables/rows/row.rs
index 667570d..4d108ac 100644
--- a/src/databases/tables/rows/row.rs
+++ b/src/databases/tables/rows/row.rs
@@ -16,14 +16,32 @@
* along with this program. If not, see .
*/
+#[derive(Debug)]
pub struct Row {
- columns: Vec,
+ pub primary_key: u32,
+ pub columns: Vec,
}
impl Row {
- pub fn new(id: u32, columns: Vec) -> Self {
+ pub fn create_row(primary_key: u32) -> Self {
Self {
- columns,
+ primary_key,
+ columns: Vec::new(),
+ }
+ }
+
+ pub fn create_column(&mut self, name: String) {
+ self.columns.push(name);
+ }
+
+ pub fn delete_column(&mut self, name: String) {
+ let mut ind = 0;
+ while ind != self.columns.len() {
+ if self.columns[ind] == name {
+ self.columns.remove(ind);
+ } else {
+ ind += 1;
+ }
}
}
}
\ No newline at end of file
diff --git a/src/databases/tables/table.rs b/src/databases/tables/table.rs
index 8d99f47..b880186 100644
--- a/src/databases/tables/table.rs
+++ b/src/databases/tables/table.rs
@@ -16,19 +16,34 @@
* along with this program. If not, see .
*/
-use std::collections::HashMap;
use crate::databases::tables::rows::row::Row;
+#[derive(Debug)]
pub struct Table {
- name: String,
- rows: HashMap,
+ pub name: String,
+ pub rows: Vec,
}
impl Table {
- pub fn new(name: String, rows: HashMap) -> Self {
+ pub fn create_table(name: String) -> Self {
Self {
name,
- rows,
+ rows: Vec::new(),
+ }
+ }
+
+ pub fn add_row(&mut self, primary_key: u32) {
+ self.rows.push(Row::create_row(primary_key));
+ }
+
+ pub fn delete_row(&mut self, primary_key: u32) {
+ let mut ind = 0;
+ while ind != self.rows.len() {
+ if self.rows[ind].primary_key == primary_key {
+ self.rows.remove(ind);
+ } else {
+ ind += 1;
+ }
}
}
}
\ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index e11417d..8aeb6e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,4 +16,33 @@
* along with this program. If not, see .
*/
-pub(crate) mod databases;
\ No newline at end of file
+pub(crate) mod databases;
+use crate::databases::database::Database;
+
+#[derive(Debug)]
+pub struct RNSQL {
+ pub databases: Vec,
+}
+
+impl RNSQL {
+ pub fn new() -> Self {
+ Self {
+ databases: Vec::new(),
+ }
+ }
+
+ pub fn add_database(&mut self, name: String) {
+ self.databases.push(Database::create_database(name));
+ }
+
+ pub fn delete_database(&mut self, name: String) {
+ let mut ind = 0;
+ while ind != self.databases.len() {
+ if self.databases[ind].name == name {
+ self.databases.remove(ind);
+ } else {
+ ind += 1;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 6f3b172..76ef0b2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,7 +15,42 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+use rapid_naive_sql::RNSQL;
+
fn main() {
- println!("database");
+ let mut project = RNSQL::new();
+
+ println!("{:#?}\n\n", project);
+
+ project.add_database(String::from("db1"));
+
+ println!("{:#?}\n\n", project);
+
+ project.databases[0].add_table(String::from("tb1"));
+
+ println!("{:#?}\n\n", project);
+
+ project.databases[0].tables[0].add_row(1);
+
+ println!("{:#?}\n\n", project);
+
+ project.databases[0].tables[0].rows[0].create_column(String::from("name"));
+
+ println!("{:#?}\n\n", project);
+
+ project.databases[0].tables[0].rows[0].delete_column(String::from("name"));
+
+ println!("{:#?}\n\n", project);
+
+ project.databases[0].tables[0].delete_row(1);
+
+ println!("{:#?}\n\n", project);
+
+ project.databases[0].delete_table(String::from("tb1"));
+
+ println!("{:#?}\n\n", project);
+
+ project.delete_database(String::from("db1"));
+
+ println!("{:#?}", project);
}
\ No newline at end of file