minor file updates
This commit is contained in:
parent
7000cdab31
commit
dc89387128
12
README.md
12
README.md
|
@ -8,12 +8,18 @@ This is a SQL database written in Rust. It will be based off of (and hopefully b
|
|||
|
||||
## Feature roadmap
|
||||
|
||||
[ ] Table creation via CREATE with varchar & integer datatype
|
||||
[X] CREATE TABLE with varchar & integer datatypes
|
||||
|
||||
[ ] SELECT * query
|
||||
[X] INSERT INTO (non-batched)
|
||||
|
||||
[X] SELECT * query
|
||||
|
||||
[ ] DELETE command
|
||||
|
||||
[ ] SELECT (filtered columns) query
|
||||
|
||||
[ ] WHERE clause for SELECT and DELETE
|
||||
|
||||
[ ] Primary Keys via B+ Tree
|
||||
|
||||
[ ] Foreign Keys
|
||||
|
@ -22,4 +28,4 @@ This is a SQL database written in Rust. It will be based off of (and hopefully b
|
|||
|
||||
[ ] Support [Postgres' messaging system](https://www.postgresql.org/docs/current/protocol-flow.html#id-1.10.6.7.3) (wire compatability)
|
||||
|
||||
... other stuff is TBD
|
||||
... other stuff is TBD
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::net::{Shutdown, TcpListener, TcpStream};
|
||||
|
@ -12,8 +11,6 @@ use parser::command::{CreateCommand, InsertCommand, SelectCommand};
|
|||
pub use table::datatypes::Datatype;
|
||||
pub use table::table::{ColumnDefinition, TableDefinition};
|
||||
|
||||
use crate::parser::command::InsertItem;
|
||||
|
||||
const BUFFER_SIZE: usize = 500;
|
||||
|
||||
fn handle_create(command: CreateCommand) -> ::anyhow::Result<TableDefinition> {
|
||||
|
@ -122,7 +119,7 @@ fn handle_select(command: SelectCommand) -> ::anyhow::Result<String> {
|
|||
|
||||
fn run_command(query: String) -> String {
|
||||
let response: String;
|
||||
if query.chars().nth(0).unwrap() == '\\' {
|
||||
if query.starts_with('\\') {
|
||||
// handle PSQL's slash commands e.g.: \dt \d
|
||||
return String::from("Slash commands are not yet supported in SQUIRREL");
|
||||
}
|
||||
|
@ -143,7 +140,7 @@ fn run_command(query: String) -> String {
|
|||
Command::Insert(insert_command) => {
|
||||
let result = handle_insert(insert_command);
|
||||
if result.is_err() {
|
||||
String::from(result.err().unwrap().to_string())
|
||||
result.err().unwrap().to_string()
|
||||
} else {
|
||||
String::from("Data inserted.")
|
||||
}
|
||||
|
@ -161,16 +158,16 @@ fn run_command(query: String) -> String {
|
|||
}
|
||||
|
||||
fn handle_client(mut stream: TcpStream) {
|
||||
let mut data = [0 as u8; BUFFER_SIZE];
|
||||
let mut data = [0_u8; BUFFER_SIZE];
|
||||
|
||||
while match stream.read(&mut data) {
|
||||
Ok(size) => {
|
||||
Ok(_size) => {
|
||||
let query_string = String::from_utf8(data.to_vec()).expect("A UTF-8 string");
|
||||
let response: String = run_command(query_string);
|
||||
|
||||
let mut response_data_size = response.len().to_le_bytes();
|
||||
stream.write(&mut response_data_size).unwrap(); // send length of message
|
||||
stream.write(response.as_bytes()).unwrap(); // send message
|
||||
let response_data_size = response.len().to_le_bytes();
|
||||
stream.write_all(&response_data_size).unwrap(); // send length of message
|
||||
stream.write_all(response.as_bytes()).unwrap(); // send message
|
||||
true
|
||||
}
|
||||
Err(_) => {
|
||||
|
@ -194,7 +191,6 @@ fn main() -> std::io::Result<()> {
|
|||
for stream in listener.incoming() {
|
||||
thread::spawn(|| {
|
||||
handle_client(stream.expect("A valid stream"));
|
||||
()
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ pub fn tokenizer(text: String) -> Vec<String> {
|
|||
}
|
||||
|
||||
if !in_quotes && parts.contains(&cur_char) {
|
||||
if cur_str.len() != 0 {
|
||||
if !cur_str.is_empty() {
|
||||
tokens.push(cur_str);
|
||||
cur_str = String::new();
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ pub fn tokenizer(text: String) -> Vec<String> {
|
|||
}
|
||||
}
|
||||
|
||||
return tokens;
|
||||
tokens
|
||||
}
|
||||
|
||||
impl Command {
|
||||
|
@ -204,7 +204,7 @@ impl Command {
|
|||
}
|
||||
}
|
||||
|
||||
return Err(anyhow!("Unexpected end of input"));
|
||||
Err(anyhow!("Unexpected end of input"))
|
||||
}
|
||||
|
||||
fn parse_select_command(tokens: &mut Vec<String>) -> ::anyhow::Result<Command> {
|
||||
|
@ -243,7 +243,7 @@ impl Command {
|
|||
}
|
||||
}
|
||||
|
||||
return Err(anyhow!("Unexpected end of input"));
|
||||
Err(anyhow!("Unexpected end of input"))
|
||||
}
|
||||
|
||||
fn parse_create_command(tokens: &mut Vec<String>) -> ::anyhow::Result<Command> {
|
||||
|
@ -280,7 +280,7 @@ impl Command {
|
|||
state = CreateParserState::FindColumnDatatype;
|
||||
}
|
||||
CreateParserState::FindColumnDatatype => {
|
||||
let dtype = Datatype::from_str(&token).unwrap();
|
||||
let dtype = Datatype::from_str(token).unwrap();
|
||||
if dtype.has_len() {
|
||||
state = CreateParserState::FindColumnLength;
|
||||
} else {
|
||||
|
@ -330,7 +330,7 @@ impl Command {
|
|||
}
|
||||
}
|
||||
|
||||
return Err(anyhow!("Unexpected end of input"));
|
||||
Err(anyhow!("Unexpected end of input"))
|
||||
}
|
||||
|
||||
pub fn from_string(command_str: String) -> ::anyhow::Result<Command> {
|
||||
|
@ -344,6 +344,7 @@ impl Command {
|
|||
_ => Err(anyhow!("Unknown command '{}'", token)),
|
||||
};
|
||||
}
|
||||
return Err(anyhow!("Unexpected end of statement"));
|
||||
|
||||
Err(anyhow!("Unexpected end of statement"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,11 +33,11 @@ impl Datatype {
|
|||
// Remove dquotes
|
||||
str_bytes.remove(0);
|
||||
str_bytes.remove(str_bytes.len() - 1);
|
||||
return Ok(str_bytes);
|
||||
Ok(str_bytes)
|
||||
}
|
||||
Datatype::Integer => {
|
||||
let val = data_val.parse::<u8>()?;
|
||||
return Ok(vec![val]);
|
||||
Ok(vec![val])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,11 +46,11 @@ impl Datatype {
|
|||
match self {
|
||||
Datatype::CharacterVarying => {
|
||||
let str_val = String::from_utf8(data_val.to_vec())?;
|
||||
return Ok(str_val);
|
||||
Ok(str_val)
|
||||
}
|
||||
Datatype::Integer => {
|
||||
let val = data_val.first().unwrap();
|
||||
return Ok(format!("{}", val));
|
||||
Ok(format!("{}", val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
pub mod table;
|
||||
pub mod datatypes;
|
||||
pub mod table;
|
||||
|
|
Loading…
Reference in a new issue