Skip to content

Remove "SQL" from types (and other renames) #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use simple_logger;
use std::fs;

use sqlparser::dialect::*;
use sqlparser::sqlparser::Parser;
use sqlparser::parser::Parser;

fn main() {
simple_logger::init().unwrap();
Expand All @@ -30,10 +30,10 @@ fn main() {
);

let dialect: Box<dyn Dialect> = match std::env::args().nth(2).unwrap_or_default().as_ref() {
"--ansi" => Box::new(AnsiSqlDialect {}),
"--ansi" => Box::new(AnsiDialect {}),
"--postgres" => Box::new(PostgreSqlDialect {}),
"--ms" => Box::new(MsSqlDialect {}),
"--generic" | "" => Box::new(GenericSqlDialect {}),
"--generic" | "" => Box::new(GenericDialect {}),
s => panic!("Unexpected parameter: {}", s),
};

Expand Down
6 changes: 3 additions & 3 deletions examples/parse_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

#![warn(clippy::all)]

use sqlparser::dialect::GenericSqlDialect;
use sqlparser::sqlparser::*;
use sqlparser::dialect::GenericDialect;
use sqlparser::parser::*;

fn main() {
let sql = "SELECT a, b, 123, myfunc(b) \
FROM table_1 \
WHERE a > b AND b < 100 \
ORDER BY a DESC, b";

let dialect = GenericSqlDialect {};
let dialect = GenericDialect {};

let ast = Parser::parse_sql(&dialect, sql.to_string()).unwrap();

Expand Down
58 changes: 29 additions & 29 deletions src/sqlast/sqltype.rs → src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::SQLObjectName;
use super::ObjectName;

/// SQL data types
#[derive(Debug, Clone, PartialEq, Hash)]
pub enum SQLType {
pub enum DataType {
/// Fixed-length character type e.g. CHAR(10)
Char(Option<u64>),
/// Variable-length character type e.g. VARCHAR(10)
Expand Down Expand Up @@ -60,44 +60,44 @@ pub enum SQLType {
/// Bytea
Bytea,
/// Custom type such as enums
Custom(SQLObjectName),
Custom(ObjectName),
/// Arrays
Array(Box<SQLType>),
Array(Box<DataType>),
}

impl ToString for SQLType {
impl ToString for DataType {
fn to_string(&self) -> String {
match self {
SQLType::Char(size) => format_type_with_optional_length("char", size),
SQLType::Varchar(size) => format_type_with_optional_length("character varying", size),
SQLType::Uuid => "uuid".to_string(),
SQLType::Clob(size) => format!("clob({})", size),
SQLType::Binary(size) => format!("binary({})", size),
SQLType::Varbinary(size) => format!("varbinary({})", size),
SQLType::Blob(size) => format!("blob({})", size),
SQLType::Decimal(precision, scale) => {
DataType::Char(size) => format_type_with_optional_length("char", size),
DataType::Varchar(size) => format_type_with_optional_length("character varying", size),
DataType::Uuid => "uuid".to_string(),
DataType::Clob(size) => format!("clob({})", size),
DataType::Binary(size) => format!("binary({})", size),
DataType::Varbinary(size) => format!("varbinary({})", size),
DataType::Blob(size) => format!("blob({})", size),
DataType::Decimal(precision, scale) => {
if let Some(scale) = scale {
format!("numeric({},{})", precision.unwrap(), scale)
} else {
format_type_with_optional_length("numeric", precision)
}
}
SQLType::Float(size) => format_type_with_optional_length("float", size),
SQLType::SmallInt => "smallint".to_string(),
SQLType::Int => "int".to_string(),
SQLType::BigInt => "bigint".to_string(),
SQLType::Real => "real".to_string(),
SQLType::Double => "double".to_string(),
SQLType::Boolean => "boolean".to_string(),
SQLType::Date => "date".to_string(),
SQLType::Time => "time".to_string(),
SQLType::Timestamp => "timestamp".to_string(),
SQLType::Interval => "interval".to_string(),
SQLType::Regclass => "regclass".to_string(),
SQLType::Text => "text".to_string(),
SQLType::Bytea => "bytea".to_string(),
SQLType::Array(ty) => format!("{}[]", ty.to_string()),
SQLType::Custom(ty) => ty.to_string(),
DataType::Float(size) => format_type_with_optional_length("float", size),
DataType::SmallInt => "smallint".to_string(),
DataType::Int => "int".to_string(),
DataType::BigInt => "bigint".to_string(),
DataType::Real => "real".to_string(),
DataType::Double => "double".to_string(),
DataType::Boolean => "boolean".to_string(),
DataType::Date => "date".to_string(),
DataType::Time => "time".to_string(),
DataType::Timestamp => "timestamp".to_string(),
DataType::Interval => "interval".to_string(),
DataType::Regclass => "regclass".to_string(),
DataType::Text => "text".to_string(),
DataType::Bytea => "bytea".to_string(),
DataType::Array(ty) => format!("{}[]", ty.to_string()),
DataType::Custom(ty) => ty.to_string(),
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/sqlast/ddl.rs → src/ast/ddl.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! AST types specific to CREATE/ALTER variants of `SQLStatement`
//! (commonly referred to as Data Definition Language, or DDL)
use super::{Expr, SQLIdent, SQLObjectName, SQLType};
use super::{DataType, Expr, Ident, ObjectName};

/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
#[derive(Debug, Clone, PartialEq, Hash)]
pub enum AlterTableOperation {
/// `ADD <table_constraint>`
AddConstraint(TableConstraint),
/// TODO: implement `DROP CONSTRAINT <name>`
DropConstraint { name: SQLIdent },
DropConstraint { name: Ident },
}

impl ToString for AlterTableOperation {
Expand All @@ -26,22 +26,22 @@ impl ToString for AlterTableOperation {
pub enum TableConstraint {
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
Unique {
name: Option<SQLIdent>,
columns: Vec<SQLIdent>,
name: Option<Ident>,
columns: Vec<Ident>,
/// Whether this is a `PRIMARY KEY` or just a `UNIQUE` constraint
is_primary: bool,
},
/// A referential integrity constraint (`[ CONSTRAINT <name> ] FOREIGN KEY (<columns>)
/// REFERENCES <foreign_table> (<referred_columns>)`)
ForeignKey {
name: Option<SQLIdent>,
columns: Vec<SQLIdent>,
foreign_table: SQLObjectName,
referred_columns: Vec<SQLIdent>,
name: Option<Ident>,
columns: Vec<Ident>,
foreign_table: ObjectName,
referred_columns: Vec<Ident>,
},
/// `[ CONSTRAINT <name> ] CHECK (<expr>)`
Check {
name: Option<SQLIdent>,
name: Option<Ident>,
expr: Box<Expr>,
},
}
Expand Down Expand Up @@ -82,14 +82,14 @@ impl ToString for TableConstraint {

/// SQL column definition
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct SQLColumnDef {
pub name: SQLIdent,
pub data_type: SQLType,
pub collation: Option<SQLObjectName>,
pub struct ColumnDef {
pub name: Ident,
pub data_type: DataType,
pub collation: Option<ObjectName>,
pub options: Vec<ColumnOptionDef>,
}

impl ToString for SQLColumnDef {
impl ToString for ColumnDef {
fn to_string(&self) -> String {
format!(
"{} {}{}",
Expand Down Expand Up @@ -122,7 +122,7 @@ impl ToString for SQLColumnDef {
/// "column options," and we allow any column option to be named.
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct ColumnOptionDef {
pub name: Option<SQLIdent>,
pub name: Option<Ident>,
pub option: ColumnOption,
}

Expand Down Expand Up @@ -153,8 +153,8 @@ pub enum ColumnOption {
/// A referential integrity constraint (`[FOREIGN KEY REFERENCES
/// <foreign_table> (<referred_columns>)`).
ForeignKey {
foreign_table: SQLObjectName,
referred_columns: Vec<SQLIdent>,
foreign_table: ObjectName,
referred_columns: Vec<Ident>,
},
// `CHECK (<expr>)`
Check(Expr),
Expand Down Expand Up @@ -187,7 +187,7 @@ impl ToString for ColumnOption {
}
}

fn format_constraint_name(name: &Option<SQLIdent>) -> String {
fn format_constraint_name(name: &Option<Ident>) -> String {
name.as_ref()
.map(|name| format!("CONSTRAINT {} ", name))
.unwrap_or_default()
Expand Down
Loading