Move code

This commit is contained in:
Chris Tsang 2021-05-09 19:14:47 +08:00
parent 00f2e125df
commit 6203d967eb
5 changed files with 109 additions and 107 deletions

View File

@ -7,5 +7,5 @@ publish = false
[dependencies]
async-std = { version = "^1.9", features = [ "attributes" ] }
sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "debug-print" ] }
sea-query = { path = "../../../sea-query" }
# sea-query = { path = "../../../sea-query" }
strum = { version = "^0.20", features = [ "derive" ] }

View File

@ -35,6 +35,40 @@ impl EntityTrait for Entity {
type Relation = Relation;
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Fruit => Entity::has_many(super::fruit::Entity)
.from(Column::Id)
.to(super::fruit::Column::CakeId)
.into(),
}
}
}
impl Related<super::fruit::Entity> for Entity {
fn to() -> RelationDef {
Relation::Fruit.def()
}
}
impl Model {
pub fn find_fruit(&self) -> Select<super::fruit::Entity> {
Entity::find_related().belongs_to::<Entity>(self)
}
}
// TODO: implement with derive macro
impl EntityName for Entity {}
@ -95,17 +129,6 @@ impl IdenStatic for Column {
}
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
}
}
}
// TODO: implement with derive macro
impl Iden for PrimaryKey {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
@ -132,27 +155,4 @@ impl PrimaryKeyOfModel<Model> for PrimaryKey {
Self::Id => Column::Id,
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Fruit => Entity::has_many(super::fruit::Entity)
.from(Column::Id)
.to(super::fruit::Column::CakeId)
.into(),
}
}
}
impl Related<super::fruit::Entity> for Entity {
fn to() -> RelationDef {
Relation::Fruit.def()
}
}
impl Model {
pub fn find_fruit(&self) -> Select<super::fruit::Entity> {
Entity::find_related().belongs_to::<Entity>(self)
}
}
}

View File

@ -35,6 +35,24 @@ impl EntityTrait for Entity {
type Relation = Relation;
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
Self::CakeId => ColumnType::Integer(None),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!()
}
}
// TODO: implement with derive macro
impl EntityName for Entity {}
@ -99,17 +117,6 @@ impl IdenStatic for Column {
}
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
Self::CakeId => ColumnType::Integer(None),
}
}
}
// TODO: implement with derive macro
impl Iden for PrimaryKey {
@ -137,10 +144,4 @@ impl PrimaryKeyOfModel<Model> for PrimaryKey {
Self::Id => Column::Id,
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!()
}
}
}

View File

@ -35,6 +35,40 @@ impl EntityTrait for Entity {
type Relation = Relation;
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Fruit => Entity::has_many(super::fruit::Entity)
.from(Column::Id)
.to(super::fruit::Column::CakeId)
.into(),
}
}
}
impl Related<super::fruit::Entity> for Entity {
fn to() -> RelationDef {
Relation::Fruit.def()
}
}
impl Model {
pub fn find_fruit(&self) -> Select<super::fruit::Entity> {
Entity::find_related().belongs_to::<Entity>(self)
}
}
// TODO: implement with derive macro
impl EntityName for Entity {}
@ -95,17 +129,6 @@ impl IdenStatic for Column {
}
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
}
}
}
// TODO: implement with derive macro
impl Iden for PrimaryKey {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
@ -132,27 +155,4 @@ impl PrimaryKeyOfModel<Model> for PrimaryKey {
Self::Id => Column::Id,
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Fruit => Entity::has_many(super::fruit::Entity)
.from(Column::Id)
.to(super::fruit::Column::CakeId)
.into(),
}
}
}
impl Related<super::fruit::Entity> for Entity {
fn to() -> RelationDef {
Relation::Fruit.def()
}
}
impl Model {
pub fn find_fruit(&self) -> Select<super::fruit::Entity> {
Entity::find_related().belongs_to::<Entity>(self)
}
}
}

View File

@ -35,6 +35,24 @@ impl EntityTrait for Entity {
type Relation = Relation;
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
Self::CakeId => ColumnType::Integer(None),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!()
}
}
// TODO: implement with derive macro
impl EntityName for Entity {}
@ -99,17 +117,6 @@ impl IdenStatic for Column {
}
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnType {
match self {
Self::Id => ColumnType::Integer(None),
Self::Name => ColumnType::String(None),
Self::CakeId => ColumnType::Integer(None),
}
}
}
// TODO: implement with derive macro
impl Iden for PrimaryKey {
@ -137,10 +144,4 @@ impl PrimaryKeyOfModel<Model> for PrimaryKey {
Self::Id => Column::Id,
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!()
}
}
}