Skip to content

Commit

Permalink
Merge branch 'master' into active-model-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 authored Oct 12, 2021
2 parents 01fecbc + 664afa4 commit a5c8290
Show file tree
Hide file tree
Showing 45 changed files with 818 additions and 65 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
- 0.2.x

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -170,7 +171,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
path: [async-std, tokio, actix_example, actix4_example, rocket_example]
path: [basic, actix_example, actix4_example, rocket_example]
steps:
- uses: actions/checkout@v2

Expand All @@ -186,6 +187,28 @@ jobs:
args: >
--manifest-path examples/${{ matrix.path }}/Cargo.toml
issues:
name: Issues
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
path: [86]
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- uses: actions-rs/cargo@v1
with:
command: build
args: >
--manifest-path issues/${{ matrix.path }}/Cargo.toml
sqlite:
name: SQLite
runs-on: ubuntu-20.04
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.2.6 - 2021-10-09

- [[#224]] [sea-orm-cli] Date & Time column type mapping
- Escape rust keywords with `r#` raw identifier

[#224]: https://github.com/SeaQL/sea-orm/pull/224

## 0.2.5 - 2021-10-06

- [[#227]] Resolve "Inserting actual none value of Option<Date> results in panic"
- [[#219]] [sea-orm-cli] Add `--tables` option
- [[#189]] Add `debug_query` and `debug_query_stmt` macro

[#227]: https://github.com/SeaQL/sea-orm/issues/227
[#219]: https://github.com/SeaQL/sea-orm/pull/219
[#189]: https://github.com/SeaQL/sea-orm/pull/189

## 0.2.4 - 2021-10-01

- [[#186]] [sea-orm-cli] Foreign key handling
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "sea-orm-macros", "sea-orm-codegen"]

[package]
name = "sea-orm"
version = "0.2.4"
version = "0.2.6"
authors = ["Chris Tsang <[email protected]>"]
edition = "2018"
description = "🐚 An async & dynamic ORM for Rust"
Expand All @@ -29,8 +29,8 @@ futures = { version = "^0.3" }
futures-util = { version = "^0.3" }
log = { version = "^0.4", optional = true }
rust_decimal = { version = "^1", optional = true }
sea-orm-macros = { version = "^0.2.4", path = "sea-orm-macros", optional = true }
sea-query = { version = "^0.16.5", features = ["thread-safe"] }
sea-orm-macros = { version = "^0.2.6", path = "sea-orm-macros", optional = true }
sea-query = { version = "^0.17.0", features = ["thread-safe"] }
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
SeaORM is a relational ORM to help you build light weight and concurrent web services in Rust.

[![Getting Started](https://img.shields.io/badge/Getting%20Started-brightgreen)](https://www.sea-ql.org/SeaORM/docs/index)
[![Usage Example](https://img.shields.io/badge/Usage%20Example-yellow)](https://github.com/SeaQL/sea-orm/tree/master/examples/async-std)
[![Usage Example](https://img.shields.io/badge/Usage%20Example-yellow)](https://github.com/SeaQL/sea-orm/tree/master/examples/basic)
[![Actix Example](https://img.shields.io/badge/Actix%20Example-blue)](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example)
[![Rocket Example](https://img.shields.io/badge/Rocket%20Example-orange)](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example)
[![Discord](https://img.shields.io/discord/873880840487206962?label=Discord)](https://discord.com/invite/uCPdDXzbdv)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "sea-orm-cli"
version = "0.2.4"
version = "0.2.6"
authors = [ "Billy Chan <[email protected]>" ]
edition = "2018"
description = "Command line utility for SeaORM"
Expand All @@ -21,7 +21,7 @@ path = "src/main.rs"
clap = { version = "^2.33.3" }
dotenv = { version = "^0.15" }
async-std = { version = "^1.9", features = [ "attributes" ] }
sea-orm-codegen = { version = "^0.2.4", path = "../sea-orm-codegen" }
sea-orm-codegen = { version = "^0.2.6", path = "../sea-orm-codegen" }
sea-schema = { version = "^0.2.9", default-features = false, features = [
"debug-print",
"sqlx-mysql",
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sea-orm-codegen"
version = "0.2.4"
version = "0.2.6"
authors = ["Billy Chan <[email protected]>"]
edition = "2018"
description = "Code Generator for SeaORM"
Expand Down
45 changes: 40 additions & 5 deletions sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::util::escape_rust_keyword;
use heck::{CamelCase, SnakeCase};
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
Expand All @@ -14,11 +15,11 @@ pub struct Column {

impl Column {
pub fn get_name_snake_case(&self) -> Ident {
format_ident!("{}", self.name.to_snake_case())
format_ident!("{}", escape_rust_keyword(self.name.to_snake_case()))
}

pub fn get_name_camel_case(&self) -> Ident {
format_ident!("{}", self.name.to_camel_case())
format_ident!("{}", escape_rust_keyword(self.name.to_camel_case()))
}

pub fn get_rs_type(&self) -> TokenStream {
Expand All @@ -27,8 +28,6 @@ impl Column {
ColumnType::Char(_)
| ColumnType::String(_)
| ColumnType::Text
| ColumnType::Time(_)
| ColumnType::Date
| ColumnType::Custom(_) => "String",
ColumnType::TinyInteger(_) => "i8",
ColumnType::SmallInteger(_) => "i16",
Expand All @@ -37,6 +36,8 @@ impl Column {
ColumnType::Float(_) => "f32",
ColumnType::Double(_) => "f64",
ColumnType::Json | ColumnType::JsonBinary => "Json",
ColumnType::Date => "Date",
ColumnType::Time(_) => "Time",
ColumnType::DateTime(_) | ColumnType::Timestamp(_) => "DateTime",
ColumnType::TimestampWithTimeZone(_) => "DateTimeWithTimeZone",
ColumnType::Decimal(_) | ColumnType::Money(_) => "Decimal",
Expand Down Expand Up @@ -194,6 +195,11 @@ mod tests {
make_col!("CAKE_FILLING_ID", ColumnType::Double(None)),
make_col!("CAKE-FILLING-ID", ColumnType::Binary(None)),
make_col!("CAKE", ColumnType::Boolean),
make_col!("date", ColumnType::Date),
make_col!("time", ColumnType::Time(None)),
make_col!("date_time", ColumnType::DateTime(None)),
make_col!("timestamp", ColumnType::Timestamp(None)),
make_col!("timestamp_tz", ColumnType::TimestampWithTimeZone(None)),
]
}

Expand All @@ -211,6 +217,11 @@ mod tests {
"cake_filling_id",
"cake_filling_id",
"cake",
"date",
"time",
"date_time",
"timestamp",
"timestamp_tz",
];
for (col, snack_case) in columns.into_iter().zip(snack_cases) {
assert_eq!(col.get_name_snake_case().to_string(), snack_case);
Expand All @@ -231,6 +242,11 @@ mod tests {
"CakeFillingId",
"CakeFillingId",
"Cake",
"Date",
"Time",
"DateTime",
"Timestamp",
"TimestampTz",
];
for (col, camel_case) in columns.into_iter().zip(camel_cases) {
assert_eq!(col.get_name_camel_case().to_string(), camel_case);
Expand All @@ -241,7 +257,21 @@ mod tests {
fn test_get_rs_type() {
let columns = setup();
let rs_types = vec![
"String", "String", "i8", "i16", "i32", "i64", "f32", "f64", "Vec<u8>", "bool",
"String",
"String",
"i8",
"i16",
"i32",
"i64",
"f32",
"f64",
"Vec<u8>",
"bool",
"Date",
"Time",
"DateTime",
"DateTime",
"DateTimeWithTimeZone",
];
for (mut col, rs_type) in columns.into_iter().zip(rs_types) {
let rs_type: TokenStream = rs_type.parse().unwrap();
Expand Down Expand Up @@ -271,6 +301,11 @@ mod tests {
"ColumnType::Double.def()",
"ColumnType::Binary.def()",
"ColumnType::Boolean.def()",
"ColumnType::Date.def()",
"ColumnType::Time.def()",
"ColumnType::DateTime.def()",
"ColumnType::Timestamp.def()",
"ColumnType::TimestampWithTimeZone.def()",
];
for (mut col, col_def) in columns.into_iter().zip(col_defs) {
let mut col_def: TokenStream = col_def.parse().unwrap();
Expand Down
72 changes: 70 additions & 2 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,18 +597,85 @@ mod tests {
name: "id".to_owned(),
}],
},
Entity {
table_name: "rust_keyword".to_owned(),
columns: vec![
Column {
name: "id".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: true,
not_null: true,
unique: false,
},
Column {
name: "testing".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "rust".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "keywords".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "type".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "typeof".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "crate".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "self".to_owned(),
col_type: ColumnType::Integer(Some(11)),
auto_increment: false,
not_null: true,
unique: false,
},
],
relations: vec![],
conjunct_relations: vec![],
primary_keys: vec![PrimaryKey {
name: "id".to_owned(),
}],
},
]
}

#[test]
fn test_gen_expanded_code_blocks() -> io::Result<()> {
let entities = setup();
const ENTITY_FILES: [&str; 5] = [
const ENTITY_FILES: [&str; 6] = [
include_str!("../../tests/expanded/cake.rs"),
include_str!("../../tests/expanded/cake_filling.rs"),
include_str!("../../tests/expanded/filling.rs"),
include_str!("../../tests/expanded/fruit.rs"),
include_str!("../../tests/expanded/vendor.rs"),
include_str!("../../tests/expanded/rust_keyword.rs"),
];

assert_eq!(entities.len(), ENTITY_FILES.len());
Expand Down Expand Up @@ -642,12 +709,13 @@ mod tests {
#[test]
fn test_gen_compact_code_blocks() -> io::Result<()> {
let entities = setup();
const ENTITY_FILES: [&str; 5] = [
const ENTITY_FILES: [&str; 6] = [
include_str!("../../tests/compact/cake.rs"),
include_str!("../../tests/compact/cake_filling.rs"),
include_str!("../../tests/compact/filling.rs"),
include_str!("../../tests/compact/fruit.rs"),
include_str!("../../tests/compact/vendor.rs"),
include_str!("../../tests/compact/rust_keyword.rs"),
];

assert_eq!(entities.len(), ENTITY_FILES.len());
Expand Down
1 change: 1 addition & 0 deletions sea-orm-codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod entity;
mod error;
mod util;

pub use entity::*;
pub use error::*;
23 changes: 23 additions & 0 deletions sea-orm-codegen/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub(crate) fn escape_rust_keyword<T>(string: T) -> String
where
T: ToString,
{
let string = string.to_string();
if RUST_KEYWORDS.iter().any(|s| s.eq(&string)) {
format!("r#{}", string)
} else if RUST_SPECIAL_KEYWORDS.iter().any(|s| s.eq(&string)) {
format!("{}_", string)
} else {
string
}
}

pub(crate) const RUST_KEYWORDS: [&str; 49] = [
"as", "async", "await", "break", "const", "continue", "dyn", "else", "enum", "extern", "false",
"fn", "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref",
"return", "static", "struct", "super", "trait", "true", "type", "union", "unsafe", "use",
"where", "while", "abstract", "become", "box", "do", "final", "macro", "override", "priv",
"try", "typeof", "unsized", "virtual", "yield",
];

pub(crate) const RUST_SPECIAL_KEYWORDS: [&str; 3] = ["crate", "Self", "self"];
30 changes: 30 additions & 0 deletions sea-orm-codegen/tests/compact/rust_keyword.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "rust_keyword")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub testing: i32,
pub rust: i32,
pub keywords: i32,
pub r#type: i32,
pub r#typeof: i32,
pub crate_: i32,
pub self_: i32,
}

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
_ => panic!("No RelationDef"),
}
}
}

impl ActiveModelBehavior for ActiveModel {}
Loading

0 comments on commit a5c8290

Please sign in to comment.