Skip to content

Commit aad6016

Browse files
committed
Added more comments to the code
1 parent 44ecc27 commit aad6016

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/sql/db/table.rs

+13
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ impl Table {
121121
}
122122
}
123123

124+
/// Returns a `bool` informing if a `Column` with a specific name exists or not
125+
///
124126
pub fn contains_column(&self, column: String) -> bool {
125127
self.columns.contains_key(&column)
126128
}
@@ -147,6 +149,9 @@ impl Table {
147149
}
148150
}
149151

152+
/// Validates if columns and values being inserted violate the UNIQUE constraint
153+
/// As a reminder the PRIMARY KEY column automatically also is a UNIQUE column.
154+
///
150155
pub fn validate_unique_constraint(
151156
&mut self,
152157
cols: &Vec<String>,
@@ -194,6 +199,14 @@ impl Table {
194199
return Ok(());
195200
}
196201

202+
/// Inserts all VALUES in its approprieta COLUMNS, using the ROWID an embedded INDEX on all ROWS
203+
/// Every `Table` keeps track of the `last_rowid` in order to facilitate what the next one would be.
204+
/// One limitation of this data structure is that we can only have one write transaction at a time, otherwise
205+
/// we could have a race condition on the last_rowid.println!
206+
///
207+
/// Since we are loosely modeling after SQLite, this is also a limitation of SQLite (allowing only one write transcation at a time),
208+
/// So we are good. :)
209+
///
197210
pub fn insert_row(&mut self, cols: &Vec<String>, values: &Vec<Vec<String>>) {
198211
// For every column in the INSERT statement
199212
for i in 0..cols.len() {

src/sql/parser/create.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct ParsedColumn {
2020

2121
/// The following structure represents a CREATE TABLE query already parsed
2222
/// and broken down into name and a Vector of `ParsedColumn` metadata
23+
///
2324
#[derive(Debug)]
2425
pub struct CreateQuery {
2526
/// name of table after parking and tokenizing of query

src/sql/parser/insert.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use sqlparser::ast::{Expr, Query, SetExpr, Statement, Value, Values};
22

33
use crate::error::{Result, SQLRiteError};
44

5+
/// The following structure represents a INSERT query already parsed
6+
/// and broken down into `table_name` a `Vec<String>` representing the `Columns`
7+
/// and `Vec<Vec<String>>` representing the list of `Rows` to be inserted
58
#[derive(Debug)]
69
pub struct InsertQuery {
710
pub table_name: String,

0 commit comments

Comments
 (0)