Skip to content

Commit

Permalink
Make examples simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Sep 28, 2024
1 parent ee234f1 commit 6937748
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 66 deletions.
12 changes: 1 addition & 11 deletions examples/diesel_sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use diesel::deserialize::{self, FromSql};
use diesel::sql_types::BigInt;
use diesel::sql_types::{Blob, Text};
use diesel::{Connection, QueryableByName, RunQueryDsl, SqliteConnection};
use sea_query::{
Alias, ColumnDef, ConditionalStatement, Expr, Func, Iden, Index, Order, Query,
SqliteQueryBuilder, Table,
};
use sea_query::{Alias, ColumnDef, Expr, Func, Iden, Order, Query, SqliteQueryBuilder, Table};
use sea_query_diesel::DieselBinder;
use serde_json::json;
use time::macros::{date, time};
Expand Down Expand Up @@ -43,13 +40,6 @@ fn main() {
.col(ColumnDef::new(Character::Meta).json().not_null())
.col(ColumnDef::new(Character::Created).date_time())
.build(SqliteQueryBuilder),
Index::create()
.name("partial_index_small_font")
.if_not_exists()
.table(Character::Table)
.col(Character::FontSize)
.and_where(Expr::col(Character::FontSize).lt(11).not())
.build(SqliteQueryBuilder),
]
.join("; ");

Expand Down
4 changes: 2 additions & 2 deletions examples/postgres/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ cargo run

Example output:
```
DROP TABLE IF EXISTS "document"; CREATE TABLE IF NOT EXISTS "document" ( "id" serial NOT NULL PRIMARY KEY, "uuid" uuid, "json_field" jsonb, "timestamp" timestamp, "timestamp_with_time_zone" timestamp with time zone, "decimal" decimal, "array" integer[] ); CREATE INDEX "partial_index_small_decimal" ON "document" ("decimal") WHERE NOT "decimal" < 11
Create table document: Ok(())
DROP TABLE IF EXISTS "document"; CREATE TABLE IF NOT EXISTS "document" ( "id" serial NOT NULL PRIMARY KEY, "json_field" jsonb, "timestamp" timestamp )
Create table document: ()
Insert into document: Ok(1)
Expand Down
11 changes: 1 addition & 10 deletions examples/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime};

use postgres::{Client, NoTls, Row};
use rust_decimal::Decimal;
use sea_query::{
ColumnDef, ColumnType, ConditionalStatement, Expr, Iden, Index, Order, PostgresQueryBuilder,
Query, Table,
};
use sea_query::{ColumnDef, ColumnType, Iden, Order, PostgresQueryBuilder, Query, Table};
use sea_query_postgres::PostgresBinder;
use time::{
macros::{date, offset, time},
Expand Down Expand Up @@ -40,12 +37,6 @@ fn main() {
.col(ColumnDef::new(Document::Decimal).decimal())
.col(ColumnDef::new(Document::Array).array(ColumnType::Integer))
.build(PostgresQueryBuilder),
Index::create()
.name("partial_index_small_decimal")
.table(Document::Table)
.col(Document::Decimal)
.and_where(Expr::col(Document::Decimal).lt(11).not())
.build(PostgresQueryBuilder),
]
.join("; ");

Expand Down
12 changes: 2 additions & 10 deletions examples/rusqlite/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use chrono::{NaiveDate, NaiveDateTime};
use rusqlite::{Connection, Result, Row};
use sea_query::{
ColumnDef, ConditionalStatement, Expr, Func, Iden, Index, Order, Query, SqliteQueryBuilder,
Table,
};
use sea_query::{ColumnDef, Expr, Func, Iden, Order, Query, SqliteQueryBuilder, Table};

use sea_query_rusqlite::RusqliteBinder;
use serde_json::{json, Value as Json};
use time::{
Expand Down Expand Up @@ -39,12 +37,6 @@ fn main() -> Result<()> {
.col(ColumnDef::new(Character::Meta).json())
.col(ColumnDef::new(Character::Created).date_time())
.build(SqliteQueryBuilder),
Index::create()
.name("partial_index_small_font")
.table(Character::Table)
.col(Character::FontSize)
.and_where(Expr::col(Character::FontSize).lt(11).not())
.build(SqliteQueryBuilder),
]
.join("; ");

Expand Down
2 changes: 0 additions & 2 deletions examples/sqlx_postgres/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Example output:
```
Create table character: Ok(PgQueryResult { rows_affected: 0 })
Create partial index: Ok(PgQueryResult { rows_affected: 0 })
Insert into character: Ok(PgQueryResult { rows_affected: 1 })
Select one from character:
Expand Down
15 changes: 1 addition & 14 deletions examples/sqlx_postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use bigdecimal::{BigDecimal, FromPrimitive};
use chrono::{NaiveDate, NaiveDateTime};
use rust_decimal::Decimal;
use sea_query::{
ColumnDef, ConditionalStatement, Expr, Func, Iden, Index, OnConflict, Order,
PostgresQueryBuilder, Query, Table,
ColumnDef, Expr, Func, Iden, OnConflict, Order, PostgresQueryBuilder, Query, Table,
};
use sea_query_binder::SqlxBinder;
use sqlx::{PgPool, Row};
Expand Down Expand Up @@ -51,18 +50,6 @@ async fn main() {
let result = sqlx::query(&sql).execute(&mut *pool).await;
println!("Create table character: {result:?}\n");

// Partial Index
let partial_index = Index::create()
.if_not_exists()
.name("partial_index_small_font")
.table(Character::Table)
.col(Character::FontSize)
.and_where(Expr::col(Character::FontSize).lt(11).not())
.build(PostgresQueryBuilder);

let index = sqlx::query(&partial_index).execute(&mut *pool).await;
println!("Create partial index: {index:?}\n");

// Create

let (sql, values) = Query::insert()
Expand Down
2 changes: 0 additions & 2 deletions examples/sqlx_sqlite/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Example output:
```
Create table character: Ok(SqliteQueryResult { changes: 0, last_insert_rowid: 0 })
Create partial index: Ok(SqliteQueryResult { changes: 0, last_insert_rowid: 0 })
Insert into character: last_insert_id = 1
Select one from character:
Expand Down
16 changes: 1 addition & 15 deletions examples/sqlx_sqlite/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use chrono::{NaiveDate, NaiveDateTime};
use sea_query::{
ColumnDef, ConditionalStatement, Expr, Func, Iden, Index, OnConflict, Order, Query,
SqliteQueryBuilder, Table,
};
use sea_query::{ColumnDef, Expr, Func, Iden, OnConflict, Order, Query, SqliteQueryBuilder, Table};
use sea_query_binder::SqlxBinder;
use serde_json::{json, Value as Json};
use sqlx::{Row, SqlitePool};
Expand Down Expand Up @@ -37,17 +34,6 @@ async fn main() {
let result = sqlx::query(&sql).execute(&pool).await;
println!("Create table character: {result:?}\n");

// Partial Index
let partial_index = Index::create()
.name("partial_index_small_font")
.table(Character::Table)
.col(Character::FontSize)
.and_where(Expr::col(Character::FontSize).lt(11).not())
.build(SqliteQueryBuilder);

let index = sqlx::query(&partial_index).execute(&pool).await;
println!("Create partial index: {index:?}\n");

// Create
let (sql, values) = Query::insert()
.into_table(Character::Table)
Expand Down

0 comments on commit 6937748

Please sign in to comment.