Skip to content

Commit 3b207c9

Browse files
committed
JSON support
1 parent 1fed20d commit 3b207c9

12 files changed

Lines changed: 55 additions & 10 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ path = "src/lib.rs"
2727
[dependencies]
2828
futures = { version = "0.3", optional = true }
2929
sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" }
30-
sea-query = { version = "0.9.3" }
31-
sqlx = { version = "0.5", optional = true }
30+
sea-query = { version = "^0" }
31+
serde = { version = "^1", features = ["derive"], optional = true }
32+
sqlx = { version = "^0", optional = true }
3233

3334
[features]
3435
debug-print = []
@@ -45,4 +46,5 @@ runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls" ]
4546
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls" ]
4647
runtime-actix-rustls = [ "sqlx/runtime-actix-rustls" ]
4748
runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls" ]
48-
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls" ]
49+
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls" ]
50+
with-serde = [ "serde" ]

src/mysql/def/char_set.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use crate as sea_schema;
24

35
/// Ref: https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html
46
#[derive(Clone, Debug, PartialEq, sea_query::Iden, sea_schema_derive::Name)]
7+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
58
#[catch = "string_to_unknown"]
69
pub enum CharSet {
710
#[iden = "armscii8"] Armscii8,
@@ -50,6 +53,7 @@ pub enum CharSet {
5053

5154
/// Ref: https://dev.mysql.com/doc/refman/8.0/en/information-schema-collation-character-set-applicability-table.html
5255
#[derive(Clone, Debug, PartialEq, sea_query::Iden, sea_schema_derive::Name)]
56+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
5357
#[catch = "string_to_unknown"]
5458
pub enum Collation {
5559
#[iden = "armscii8_general_ci"] Armscii8GeneralCi,

src/mysql/def/column.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use super::Type;
24

35
#[derive(Clone, Debug, PartialEq)]
6+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
47
pub struct ColumnInfo {
58
/// The name of the column
69
pub name: String,
@@ -23,6 +26,7 @@ pub struct ColumnInfo {
2326
pub type ColumnType = Type;
2427

2528
#[derive(Clone, Debug, PartialEq)]
29+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
2630
pub enum ColumnKey {
2731
/// This column is not the first column of any key
2832
NotKey,
@@ -35,12 +39,14 @@ pub enum ColumnKey {
3539
}
3640

3741
#[derive(Clone, Debug, PartialEq)]
42+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
3843
pub struct ColumnDefault {
3944
/// default value expression
4045
pub expr: String,
4146
}
4247

4348
#[derive(Clone, Debug, Default, PartialEq)]
49+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
4450
pub struct ColumnExtra {
4551
/// Auto increment
4652
pub auto_increment: bool,

src/mysql/def/foreign_key.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use crate as sea_schema;
24

35
#[derive(Clone, Debug, PartialEq)]
6+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
47
pub struct ForeignKeyInfo {
58
/// The name of the foreign key
69
pub name: String,
@@ -17,6 +20,7 @@ pub struct ForeignKeyInfo {
1720
}
1821

1922
#[derive(Clone, Debug, PartialEq, sea_schema_derive::Name)]
23+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
2024
pub enum ForeignKeyAction {
2125
#[name = "CASCADE"] Cascade,
2226
#[name = "SET NULL"] SetNull,

src/mysql/def/index.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use crate as sea_schema;
24

35
#[derive(Clone, Debug, PartialEq)]
6+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
47
pub struct IndexInfo {
58
/// Does this index requires unique values
69
pub unique: bool,
@@ -23,13 +26,15 @@ pub struct IndexInfo {
2326
}
2427

2528
#[derive(Clone, Debug, PartialEq)]
29+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
2630
pub enum IndexOrder {
2731
Ascending,
2832
Descending,
2933
Unordered,
3034
}
3135

3236
#[derive(Clone, Debug, PartialEq, sea_schema_derive::Name)]
37+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
3338
pub enum IndexType {
3439
#[name = "BTREE"] BTree,
3540
#[name = "FULLTEXT"] FullText,

src/mysql/def/schema.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use super::*;
24

35
#[derive(Clone, Debug, PartialEq)]
6+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
47
pub struct Schema {
58
pub system: SystemInfo,
69
pub tables: Vec<TableDef>,
710
}
811

912
#[derive(Clone, Debug, PartialEq)]
13+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
1014
pub struct TableDef {
1115
pub info: TableInfo,
1216
pub columns: Vec<ColumnInfo>,

src/mysql/def/storage_engine.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use crate as sea_schema;
24

35
#[derive(Clone, Debug, PartialEq, sea_query::Iden, sea_schema_derive::Name)]
6+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
47
#[catch = "string_to_unknown"]
58
pub enum StorageEngine {
69
#[iden = "ARCHIVE"] Archive,

src/mysql/def/system.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
#[derive(Clone, Debug, Default, PartialEq)]
4+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
25
pub struct SystemInfo {
36
/// The version number converted to integer using the following formula:
47
/// major_version * 10000 + minor_version * 100 + sub_version
@@ -32,15 +35,13 @@ mod tests {
3235

3336
#[test]
3437
fn test_0() {
35-
let mut system = SystemInfo::default();
36-
system.version = 50110;
38+
let system = SystemInfo { version: 50110, ..Default::default() };
3739
assert_eq!(system.version_string(), "5.1.10".to_owned());
3840
}
3941

4042
#[test]
4143
fn test_1() {
42-
let mut system = SystemInfo::default();
43-
system.version = 80023;
44+
let system = SystemInfo { version: 80023, ..Default::default() };
4445
assert_eq!(system.version_string(), "8.0.23".to_owned());
4546
}
4647
}

src/mysql/def/table.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
use super::{CharSet, Collation, StorageEngine};
24

35
#[derive(Clone, Debug, PartialEq)]
6+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
47
pub struct TableInfo {
58
/// The name of the table
69
pub name: String,

src/mysql/def/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#[cfg(feature="with-serde")] use serde::{Serialize, Deserialize};
2+
13
#[derive(Clone, Debug, PartialEq)]
4+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
25
/// All built-in types of MySQL, excluding synonyms
36
pub enum Type {
47
Serial(NumericAttr),
@@ -46,6 +49,7 @@ pub enum Type {
4649
}
4750

4851
#[derive(Clone, Debug, Default, PartialEq)]
52+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
4953
pub struct NumericAttr {
5054
/// For integer types, M is the maximum display width (deprecated).
5155
/// For decimal types, M is the total number of digits.
@@ -59,35 +63,41 @@ pub struct NumericAttr {
5963
}
6064

6165
#[derive(Clone, Debug, Default, PartialEq)]
66+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
6267
pub struct TimeAttr {
6368
pub fractional: Option<u32>,
6469
}
6570

6671
#[derive(Clone, Debug, Default, PartialEq)]
72+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
6773
pub struct StringAttr {
6874
pub length: Option<u32>,
6975
pub charset_name: Option<String>,
7076
pub collation_name: Option<String>,
7177
}
7278

7379
#[derive(Clone, Debug, Default, PartialEq)]
80+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
7481
pub struct BlobAttr {
7582
pub length: Option<u32>,
7683
}
7784

7885
#[derive(Clone, Debug, Default, PartialEq)]
86+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
7987
pub struct EnumDef {
8088
pub values: Vec<String>,
8189
pub attr: StringAttr,
8290
}
8391

8492
#[derive(Clone, Debug, Default, PartialEq)]
93+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
8594
pub struct SetDef {
8695
pub members: Vec<String>,
8796
pub attr: StringAttr,
8897
}
8998

9099
#[derive(Clone, Debug, Default, PartialEq)]
100+
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
91101
pub struct GeometryAttr {
92102
pub srid: Option<u32>,
93103
}

0 commit comments

Comments
 (0)