Skip to content

Commit

Permalink
Derive PartialOrd, Ord, and Copy whenever possible (#717)
Browse files Browse the repository at this point in the history
This allow other projects to use our structures inside others that need
those.
  • Loading branch information
AugustoFKL committed Nov 30, 2022
1 parent c429197 commit 5e1d9f8
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 106 deletions.
10 changes: 5 additions & 5 deletions src/ast/data_type.rs
Expand Up @@ -22,7 +22,7 @@ use crate::ast::ObjectName;
use super::value::escape_single_quote_string;

/// SQL data types
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum DataType {
/// Fixed-length character type e.g. CHARACTER(10)
Expand Down Expand Up @@ -335,7 +335,7 @@ fn format_datetime_precision_and_tz(
///
/// This is more related to a display information than real differences between each variant. To
/// guarantee compatibility with the input query we must maintain its exact information.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TimezoneInfo {
/// No information about time zone. E.g., TIMESTAMP
Expand Down Expand Up @@ -382,7 +382,7 @@ impl fmt::Display for TimezoneInfo {
/// following the 2016 [standard].
///
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#exact-numeric-type
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ExactNumberInfo {
/// No additional information e.g. `DECIMAL`
Expand Down Expand Up @@ -412,7 +412,7 @@ impl fmt::Display for ExactNumberInfo {
/// Information about [character length][1], including length and possibly unit.
///
/// [1]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-length
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CharacterLength {
/// Default (if VARYING) or maximum (if not VARYING) length
Expand All @@ -434,7 +434,7 @@ impl fmt::Display for CharacterLength {
/// Possible units for characters, initially based on 2016 ANSI [standard][1].
///
/// [1]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#char-length-units
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum CharLengthUnits {
/// CHARACTERS unit
Expand Down
18 changes: 9 additions & 9 deletions src/ast/ddl.rs
Expand Up @@ -25,7 +25,7 @@ use crate::ast::{display_comma_separated, display_separated, DataType, Expr, Ide
use crate::tokenizer::Token;

/// An `ALTER TABLE` (`Statement::AlterTable`) operation
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum AlterTableOperation {
/// `ADD <table_constraint>`
Expand Down Expand Up @@ -201,7 +201,7 @@ impl fmt::Display for AlterTableOperation {
}

/// An `ALTER COLUMN` (`Statement::AlterTable`) operation
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum AlterColumnOperation {
/// `SET NOT NULL`
Expand Down Expand Up @@ -244,7 +244,7 @@ impl fmt::Display for AlterColumnOperation {

/// A table-level constraint, specified in a `CREATE TABLE` or an
/// `ALTER TABLE ADD <constraint>` statement.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TableConstraint {
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
Expand Down Expand Up @@ -407,7 +407,7 @@ impl fmt::Display for TableConstraint {
/// statements of `MySQL` [(1)].
///
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/create-table.html
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum KeyOrIndexDisplay {
/// Nothing to display
Expand Down Expand Up @@ -442,7 +442,7 @@ impl fmt::Display for KeyOrIndexDisplay {
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/create-table.html
/// [2]: https://dev.mysql.com/doc/refman/8.0/en/create-index.html
/// [3]: https://www.postgresql.org/docs/14/sql-createindex.html
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum IndexType {
BTree,
Expand All @@ -460,7 +460,7 @@ impl fmt::Display for IndexType {
}

/// SQL column definition
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ColumnDef {
pub name: Ident,
Expand Down Expand Up @@ -495,7 +495,7 @@ impl fmt::Display for ColumnDef {
/// For maximum flexibility, we don't distinguish between constraint and
/// non-constraint options, lumping them all together under the umbrella of
/// "column options," and we allow any column option to be named.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ColumnOptionDef {
pub name: Option<Ident>,
Expand All @@ -510,7 +510,7 @@ impl fmt::Display for ColumnOptionDef {

/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
/// TABLE` statement.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ColumnOption {
/// `NULL`
Expand Down Expand Up @@ -597,7 +597,7 @@ fn display_constraint_name(name: &'_ Option<Ident>) -> impl fmt::Display + '_ {
/// { RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT }`
///
/// Used in foreign key constraints in `ON UPDATE` and `ON DELETE` options.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ReferentialAction {
Restrict,
Expand Down

0 comments on commit 5e1d9f8

Please sign in to comment.