Skip to content

Commit a7b2571

Browse files
committed
Changelog; doc test
1 parent 158f091 commit a7b2571

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

CHANGELOG.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,39 @@ pub struct TableName(pub Option<SchemaName>, pub DynIden);
5656
assert_eq!(std::mem::size_of::<Value>(), 32);
5757
```
5858
* `impl From<Expr> for Condition`. Now you can use `Expr` instead of `ConditionExpression`, which has been removed from the public API https://github.com/SeaQL/sea-query/pull/915
59+
* Replaced `serial` with `GENERATED BY DEFAULT AS IDENTITY` (Postgres) https://github.com/SeaQL/sea-query/pull/918
60+
```rust
61+
let table = Table::create()
62+
.table(Char::Table)
63+
.col(ColumnDef::new(Char::Id).integer().not_null().auto_increment().primary_key())
64+
.to_owned();
5965

60-
### Breaking Changes
66+
assert_eq!(
67+
table.to_string(PostgresQueryBuilder),
68+
[
69+
r#"CREATE TABLE "character" ("#,
70+
r#""id" integer GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,"#,
71+
r#")"#,
72+
].join(" ")
73+
);
74+
75+
// if you needed to support legacy system you can still do:
76+
let table = Table::create()
77+
.table(Char::Table)
78+
.col(ColumnDef::new(Char::Id).custom("serial").not_null().primary_key())
79+
.to_owned();
80+
81+
assert_eq!(
82+
table.to_string(PostgresQueryBuilder),
83+
[
84+
r#"CREATE TABLE "character" ("#,
85+
r#""id" serial NOT NULL PRIMARY KEY"#,
86+
r#")"#,
87+
].join(" ")
88+
);
89+
```
6190

62-
* Replace `serial` with `GENERATED BY DEFAULT AS IDENTITY`
91+
### Breaking Changes
6392

6493
* Removed inherent `SimpleExpr` methods that duplicate `ExprTrait`. If you encounter the following error, please add `use sea_query::ExprTrait` in scope https://github.com/SeaQL/sea-query/pull/890
6594
```rust
@@ -206,7 +235,7 @@ ALTER TYPE "font" RENAME TO "typeface"
206235

207236
### New features
208237

209-
* Support for creating functional indexes in PostgreSQL and MySQL https://github.com/SeaQL/sea-query/pull/869
238+
* Support for creating functional indexes in Postgres and MySQL https://github.com/SeaQL/sea-query/pull/869
210239

211240
### Enhancements
212241

src/table/column.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,42 @@ impl ColumnDef {
602602
}
603603

604604
/// Use a custom type on this column.
605+
///
606+
/// # Example
607+
///
608+
/// ```
609+
/// use sea_query::{*, tests_cfg::*};
610+
///
611+
/// let table = Table::create()
612+
/// .table(Char::Table)
613+
/// .col(ColumnDef::new(Char::Id).custom("new_type").not_null().primary_key())
614+
/// .to_owned();
615+
///
616+
/// assert_eq!(
617+
/// table.to_string(MysqlQueryBuilder),
618+
/// [
619+
/// r#"CREATE TABLE `character` ("#,
620+
/// r#"`id` new_type NOT NULL PRIMARY KEY"#,
621+
/// r#")"#,
622+
/// ].join(" ")
623+
/// );
624+
/// assert_eq!(
625+
/// table.to_string(PostgresQueryBuilder),
626+
/// [
627+
/// r#"CREATE TABLE "character" ("#,
628+
/// r#""id" new_type NOT NULL PRIMARY KEY"#,
629+
/// r#")"#,
630+
/// ].join(" ")
631+
/// );
632+
/// assert_eq!(
633+
/// table.to_string(SqliteQueryBuilder),
634+
/// [
635+
/// r#"CREATE TABLE "character" ("#,
636+
/// r#""id" new_type NOT NULL PRIMARY KEY"#,
637+
/// r#")"#,
638+
/// ].join(" ")
639+
/// );
640+
/// ```
605641
pub fn custom<T>(&mut self, name: T) -> &mut Self
606642
where
607643
T: IntoIden,

0 commit comments

Comments
 (0)