Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Add smallserial and bigserial column types #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/backend/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ impl SqlGenerator for Pg {
Primary => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
Integer => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
Serial => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
SmallSerial => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
BigSerial => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
Float => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
Double => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
UUID => format!("{}\"{}\" {}", Pg::prefix(ex), name, Pg::print_type(bt, schema)),
Expand Down Expand Up @@ -210,6 +212,8 @@ impl Pg {
Primary => format!("SERIAL PRIMARY KEY NOT NULL"),
Integer => format!("INTEGER"),
Serial => format!("SERIAL"),
SmallSerial => format!("SMALLSERIAL"),
BigSerial => format!("BIGSERIAL"),
Float => format!("FLOAT"),
Double => format!("DOUBLE PRECISION"),
UUID => format!("UUID"),
Expand Down
24 changes: 24 additions & 0 deletions src/tests/pg/add_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ fn integer() {
assert_eq!(String::from("ADD COLUMN \"Integer\" INTEGER NOT NULL"), sql);
}

#[test]
fn serial() {
let sql = Pg::add_column(true, None, "Serial", &types::serial());
assert_eq!(String::from("ADD COLUMN \"Serial\" SERIAL NOT NULL"), sql);
}

#[test]
fn big_serial() {
let sql = Pg::add_column(true, None, "BigSerial", &types::big_serial());
assert_eq!(
String::from("ADD COLUMN \"BigSerial\" BIGSERIAL NOT NULL"),
sql
);
}

#[test]
fn small_serial() {
let sql = Pg::add_column(true, None, "SmallSerial", &types::small_serial());
assert_eq!(
String::from("ADD COLUMN \"SmallSerial\" SMALLSERIAL NOT NULL"),
sql
);
}

#[test]
fn float() {
let sql = Pg::add_column(true, None, "Float", &types::float());
Expand Down
11 changes: 10 additions & 1 deletion src/types/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ pub fn integer() -> Type {
Type::new(BaseType::Integer)
}

/// Create an auto-incrementing integer type
/// Create an auto-incrementing 4 integer type
pub fn serial() -> Type {
Type::new(BaseType::Serial)
}

/// Create an auto-incrementing 2 byte integer type
pub fn small_serial() -> Type {
Type::new(BaseType::SmallSerial)
}

/// Create an auto-incrementing 8 byte integer type
pub fn big_serial() -> Type {
Type::new(BaseType::BigSerial)
}
/// A 32-bit floating point type
pub fn float() -> Type {
Type::new(BaseType::Float)
Expand Down
6 changes: 5 additions & 1 deletion src/types/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ pub enum BaseType {
Primary,
/// Simple integer
Integer,
/// An integer that as a default value of the next biggest number
/// An integer that as a default value of the next biggest number (4 bytes)
Serial,
/// An integer that as a default value of the next biggest number (2 bytes)
SmallSerial,
/// An integer that as a default value of the next biggest number (8 bytes)
BigSerial,
/// Floating point number
Float,
/// Like Float but `~ ~ d o u b l e p r e c i s i o n ~ ~`
Expand Down