Update examples

This commit is contained in:
Chris Tsang 2021-08-23 15:23:36 +08:00
parent 8437f88525
commit 3f7de132aa
18 changed files with 98 additions and 4 deletions

View File

@ -27,7 +27,6 @@ jobs:
command: test command: test
args: > args: >
--all --all
--exclude 'sea-orm-example-*'
cli: cli:
name: CLI name: CLI
@ -83,6 +82,18 @@ jobs:
--features default,sqlx-${{ matrix.database }},runtime-${{ matrix.runtime }}-${{ matrix.tls }} --features default,sqlx-${{ matrix.database }},runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--no-run --no-run
- uses: actions-rs/cargo@v1
with:
command: build
args: >
--path examples/async-std
- uses: actions-rs/cargo@v1
with:
command: build
args: >
--path examples/tokio
sqlite: sqlite:
name: SQLite name: SQLite
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04

View File

@ -3,7 +3,6 @@ members = [
".", ".",
"sea-orm-macros", "sea-orm-macros",
"sea-orm-codegen", "sea-orm-codegen",
"examples/sqlx",
] ]
[package] [package]

View File

@ -1,5 +1,8 @@
[workspace]
# A separate workspace
[package] [package]
name = "sea-orm-example-sqlx" name = "sea-orm-example-async-std"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2018"
publish = false publish = false

12
examples/tokio/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[workspace]
# A separate workspace
[package]
name = "sea-orm-example-tokio"
version = "0.1.0"
edition = "2018"
publish = false
[dependencies]
sea-orm = { path = "../../", features = [ "sqlx-all", "runtime-tokio-native-tls" ] }
tokio = { version = "1", features = ["full"] }

View File

@ -0,0 +1,55 @@
use sea_orm::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"cake"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model {
pub id: i32,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Name,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
fn auto_increment() -> bool {
true
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::String(None).def(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
unreachable!()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -0,0 +1,14 @@
mod cake;
use sea_orm::*;
#[tokio::main]
pub async fn main() {
let db = Database::connect("sql://sea:sea@localhost/bakery")
.await
.unwrap();
tokio::spawn(async move {
cake::Entity::find().one(&db).await.unwrap();
})
.await.unwrap();
}

View File

@ -1,5 +1,5 @@
[workspace] [workspace]
# A separate workspace for sea-orm-cli # A separate workspace
[package] [package]
name = "sea-orm-cli" name = "sea-orm-cli"