Skip to content

Instantly share code, notes, and snippets.

View joaoh82's full-sized avatar

João Henrique Machado Silva joaoh82

View GitHub Profile
@joaoh82
joaoh82 / sqlrite-error-mod-part2.rs
Created February 23, 2021 09:33
SQLRite - error module - Part 2
use thiserror::Error;
use std::{result};
use sqlparser::parser::ParserError;
pub type Result<T> = result::Result<T, SQLRiteError>;
#[derive(Error, Debug, PartialEq)]
pub enum SQLRiteError {
@joaoh82
joaoh82 / sqlrite-sql-parser-create-mod-part2.rs
Created February 23, 2021 08:51
SQLRite - sql::parser::create module - Part 2
use sqlparser::ast::{ColumnOption, DataType, ObjectName, Statement};
use crate::error::{SQLRiteError, Result};
// Represents Columns in a table
#[derive(PartialEq, Debug)]
pub struct ParsedColumn {
pub name: String,
pub datatype: String,
pub is_pk: bool,
@joaoh82
joaoh82 / sqlrite-sql-module-part2.rs
Created February 23, 2021 08:07
SQLRite - sql module - Part 2
mod parser;
pub mod tokenizer;
use parser::create::{CreateQuery};
use sqlparser::ast::{Statement};
use sqlparser::dialect::SQLiteDialect;
use sqlparser::parser::{Parser, ParserError};
use crate::error::{SQLRiteError, Result};
@joaoh82
joaoh82 / sqlrite-meta-command.rs
Created February 22, 2021 21:58
SQLRite - meta_command/mod.rs - Part 2
use crate::error::{Result, SQLRiteError};
use std::fmt;
#[derive(Debug, PartialEq)]
pub enum MetaCommand {
Exit,
Help,
Open(String),
Unknown,
@joaoh82
joaoh82 / sqlrite-main-part2.rs
Created February 22, 2021 20:56
SQLRite - main.rs - Part 2
extern crate clap;
mod meta_command;
mod repl;
mod sql;
mod error;
use repl::{REPLHelper, get_config, get_command_type, CommandType};
use meta_command::{handle_meta_command};
use sql::{process_command};
@joaoh82
joaoh82 / rust-sqlite.sh
Created February 15, 2021 18:55
rust-sqlite.sh
$ ./rust_sqlite
Rust-SQLite - 0.1.0
Enter .exit to quit.
Enter .help for usage hints.
Connected to a transient in-memory database.
Use '.open FILENAME' to reopen on a persistent database.
rust-sqlite | 1> random command;
Error: unknown command or invalid arguments: 'random command;'. Enter '.help'
rust-sqlite | 2> .exit
$
@joaoh82
joaoh82 / rust-sqlite-repl-module-part1.rs
Last active February 15, 2021 22:04
Rust-SQLite - repl/mod.rs - Part 1
use std::borrow::Cow::{self, Borrowed, Owned};
use rustyline_derive::{Helper, Completer};
use rustyline::error::ReadlineError;
use rustyline::config::OutputStreamType;
use rustyline::{CompletionType, Config, Context, EditMode};
use rustyline::validate::{MatchingBracketValidator, Validator};
use rustyline::validate::{ValidationContext, ValidationResult};
use rustyline::hint::{Hinter, HistoryHinter};
use rustyline::highlight::{Highlighter, MatchingBracketHighlighter};
@joaoh82
joaoh82 / rust-sqlite-main-part1.rs
Created February 15, 2021 18:12
Rust-SQLite - main.rs - Part 1
extern crate clap;
mod repl;
use repl::{REPLHelper, get_config};
use rustyline::error::ReadlineError;
use rustyline::{Editor};
use clap::{App, crate_version};
package gocontext
import (
"context"
"net/http"
)
type SomeMiddleware interface {
HandleHTTPC(ctx context.Context, rw http.ResponseWriter, req *http.Request, next http.Handler)
}
package gocontext
import (
"context"
"net/http"
)
type SomeMiddleware interface {
HandleHTTPC(ctx context.Context, rw http.ResponseWriter, req *http.Request, next http.Handler)
}