Skip to content
2 changes: 1 addition & 1 deletion butane/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use butane_core::many::Many;
pub use butane_core::migrations;
pub use butane_core::query;
pub use butane_core::{
AsPrimaryKey, DataObject, DataResult, Error, FieldType, FromSql, ObjectState, PrimaryKeyType,
AsPrimaryKey, AutoPk, DataObject, DataResult, Error, FieldType, FromSql, PrimaryKeyType,
Result, SqlType, SqlVal, SqlValRef, ToSql,
};

Expand Down
18 changes: 4 additions & 14 deletions butane/tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![allow(clippy::disallowed_names)]

use butane::db::Connection;
use butane::{butane_type, find, model, query};
use butane::{butane_type, find, model, query, AutoPk, ForeignKey};
use butane::{colname, prelude::*};
use butane::{ForeignKey, ObjectState};
#[cfg(feature = "datetime")]
use chrono::{naive::NaiveDateTime, offset::Utc, DateTime};
use serde::Serialize;
Expand Down Expand Up @@ -32,7 +31,6 @@ impl Foo {
bar: 0,
baz: String::new(),
blobbity: Vec::new(),
state: ObjectState::default(),
}
}
}
Expand All @@ -49,23 +47,20 @@ impl Bar {
Bar {
name: name.to_string(),
foo: foo.into(),
state: ObjectState::default(),
}
}
}

#[model]
struct Baz {
#[auto]
id: i64,
id: AutoPk<i64>,
text: String,
}
impl Baz {
fn new(text: &str) -> Self {
Baz {
id: -1, // will be set automatically when saved
id: AutoPk::default(),
text: text.to_string(),
state: ObjectState::default(),
}
}
}
Expand All @@ -76,10 +71,7 @@ struct HasOnlyPk {
}
impl HasOnlyPk {
fn new(id: i64) -> Self {
HasOnlyPk {
id,
state: ObjectState::default(),
}
HasOnlyPk { id }
}
}

Expand All @@ -94,7 +86,6 @@ impl SelfReferential {
SelfReferential {
id,
reference: None,
state: ObjectState::default(),
}
}
}
Expand Down Expand Up @@ -349,7 +340,6 @@ fn basic_time(conn: Connection) {
naive: now.naive_utc(),
utc: now,
when: now,
state: ObjectState::default(),
};
time.save(&conn).unwrap();

Expand Down
5 changes: 1 addition & 4 deletions butane/tests/common/blog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use butane::prelude::*;
use butane::{dataresult, model};
use butane::{db::Connection, ForeignKey, Many, ObjectState};
use butane::{db::Connection, ForeignKey, Many};
#[cfg(feature = "datetime")]
use chrono::{naive::NaiveDateTime, offset::Utc};

Expand All @@ -19,7 +19,6 @@ impl Blog {
Blog {
id,
name: name.to_string(),
state: ObjectState::default(),
}
}
}
Expand Down Expand Up @@ -65,7 +64,6 @@ impl Post {
likes: 0,
tags: Many::new(),
blog: ForeignKey::from(blog),
state: ObjectState::default(),
}
}
}
Expand Down Expand Up @@ -98,7 +96,6 @@ impl Tag {
pub fn new(tag: &str) -> Self {
Tag {
tag: tag.to_string(),
state: ObjectState::default(),
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions butane/tests/custom_enum_derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use butane::db::Connection;
use butane::prelude::*;
use butane::{model, query};
use butane::{FieldType, FromSql, ObjectState, SqlVal, ToSql};
use butane::{FieldType, FromSql, SqlVal, ToSql};

use butane_test_helper::*;

Expand All @@ -21,11 +21,7 @@ struct HasCustomField2 {
}
impl HasCustomField2 {
fn new(id: i64, frob: Whatsit) -> Self {
HasCustomField2 {
id,
frob,
state: ObjectState::default(),
}
HasCustomField2 { id, frob }
}
}

Expand Down
12 changes: 4 additions & 8 deletions butane/tests/custom_pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
mod custom_pg {
use butane::custom::{SqlTypeCustom, SqlValRefCustom};
use butane::prelude::*;
use butane::{butane_type, db::Connection, model, ObjectState};
use butane::{FieldType, FromSql, SqlType, SqlVal, SqlValRef, ToSql};
use butane::{butane_type, db::Connection, model};
use butane::{AutoPk, FieldType, FromSql, SqlType, SqlVal, SqlValRef, ToSql};
use butane_test_helper::{maketest, maketest_pg};

use std::result::Result;
Expand Down Expand Up @@ -53,18 +53,16 @@ mod custom_pg {
#[model]
#[derive(Debug, PartialEq)]
struct Trip {
#[auto]
id: i64,
id: AutoPk<i64>,
pt_from: Point,
pt_to: Point,
}

fn roundtrip_custom(conn: Connection) {
let mut trip = Trip {
id: -1,
id: AutoPk::uninitialized(),
pt_from: Point::new(0.0, 0.0),
pt_to: Point::new(8.0, 9.0),
state: ObjectState::default(),
};
trip.save(&conn).unwrap();

Expand All @@ -81,15 +79,13 @@ mod custom_pg {
id: -1,
pt_from: origin.clone(),
pt_to: Point::new(8.0, 9.0),
state: ObjectState::default(),
};
trip1.save(&conn).unwrap();

let mut trip2 = Trip {
id: -1,
pt_from: Point::new(1.1, 2.0),
pt_to: Point::new(7.0, 6.0),
state: ObjectState::default(),
};
trip2.save(&conn).unwrap();

Expand Down
8 changes: 2 additions & 6 deletions butane/tests/custom_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use butane::db::Connection;
use butane::prelude::*;
use butane::{butane_type, model, query};
use butane::{FieldType, FromSql, ObjectState, SqlType, SqlVal, SqlValRef, ToSql};
use butane::{FieldType, FromSql, SqlType, SqlVal, SqlValRef, ToSql};

use butane_test_helper::*;

Expand Down Expand Up @@ -57,11 +57,7 @@ struct HasCustomField {
}
impl HasCustomField {
fn new(id: i64, frob: Frobnozzle) -> Self {
HasCustomField {
id,
frob,
state: ObjectState::default(),
}
HasCustomField { id, frob }
}
}

Expand Down
11 changes: 2 additions & 9 deletions butane/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

use butane::model;
use butane::prelude::*;
use butane::{db::Connection, FieldType, ObjectState};
use butane::{db::Connection, FieldType};
use serde::{Deserialize, Serialize};
use serde_json::Value;

Expand All @@ -23,7 +23,6 @@ impl FooJJ {
id,
val: Value::default(),
bar: 0,
state: ObjectState::default(),
}
}
}
Expand Down Expand Up @@ -88,7 +87,6 @@ impl FooHH {
id,
val: HashMap::<String, String>::default(),
bar: 0,
state: ObjectState::default(),
}
}
}
Expand Down Expand Up @@ -133,7 +131,6 @@ impl FooHHO {
id,
val: HashMap::<String, HashedObject>::default(),
bar: 0,
state: ObjectState::default(),
}
}
}
Expand Down Expand Up @@ -179,11 +176,7 @@ struct OuterFoo {
}
impl OuterFoo {
fn new(id: i64, bar: InlineFoo) -> Self {
OuterFoo {
id,
bar,
state: ObjectState::default(),
}
OuterFoo { id, bar }
}
}

Expand Down
20 changes: 7 additions & 13 deletions butane/tests/many.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use butane::db::Connection;
use butane::prelude::*;
use butane::{model, query::OrderDirection, Many, ObjectState};
use butane::{model, query::OrderDirection, AutoPk, Many};

use butane_test_helper::testall;

Expand All @@ -12,45 +12,40 @@ use common::blog::{create_tag, Blog, Post, Tag};

#[model]
struct AutoPkWithMany {
#[auto]
id: i64,
id: AutoPk<i64>,
tags: Many<Tag>,
items: Many<AutoItem>,
}
impl AutoPkWithMany {
fn new() -> Self {
AutoPkWithMany {
id: -1,
id: AutoPk::uninitialized(),
tags: Many::default(),
items: Many::default(),
state: ObjectState::default(),
}
}
}

#[model]
#[table = "renamed_many_table"]
struct RenamedAutoPkWithMany {
#[auto]
id: i64,
id: AutoPk<i64>,
tags: Many<Tag>,
items: Many<AutoItem>,
}
impl RenamedAutoPkWithMany {
fn new() -> Self {
RenamedAutoPkWithMany {
id: -1,
id: AutoPk::uninitialized(),
tags: Many::default(),
items: Many::default(),
state: ObjectState::default(),
}
}
}

#[model]
struct AutoItem {
#[auto]
id: i64,
id: AutoPk<i64>,
val: String,
}

Expand Down Expand Up @@ -192,9 +187,8 @@ testall!(can_add_to_many_before_save);

fn cant_add_unsaved_to_many(_conn: Connection) {
let unsaved_item = AutoItem {
id: -1,
id: AutoPk::uninitialized(),
val: "shiny".to_string(),
state: ObjectState::default(),
};
let mut obj = AutoPkWithMany::new();
obj.items
Expand Down
3 changes: 1 addition & 2 deletions butane/tests/migration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ fn current_migration_auto_attribute() {
let tokens = quote! {
#[derive(PartialEq, Eq, Debug, Clone)]
struct Foo {
#[auto]
id: i64,
id: AutoPk<i64>,
bar: String,
}
};
Expand Down
6 changes: 1 addition & 5 deletions butane/tests/nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ struct WithNullable {
}
impl WithNullable {
fn new(id: i64) -> Self {
WithNullable {
id,
foo: None,
state: butane::ObjectState::default(),
}
WithNullable { id, foo: None }
}
}

Expand Down
8 changes: 2 additions & 6 deletions butane/tests/uuid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use butane::db::Connection;
use butane::model;
use butane::prelude::*;
use butane::{db::Connection, ObjectState};
use uuid_for_test::Uuid;

use butane_test_helper::*;
Expand All @@ -13,11 +13,7 @@ struct FooUU {
}
impl FooUU {
fn new(id: Uuid) -> Self {
FooUU {
id,
bar: 0,
state: ObjectState::default(),
}
FooUU { id, bar: 0 }
}
}

Expand Down
7 changes: 1 addition & 6 deletions butane_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ mod filter;
/// ## Helper Attributes
/// * `#[table = "NAME"]` used on the struct to specify the name of the table (defaults to struct name)
/// * `#[pk]` on a field to specify that it is the primary key.
/// * `#[auto]` on a field indicates that the field's value is
/// initialized based on serial/auto-increment. Currently supported
/// only on the primary key and only if the primary key is an integer
/// type
/// * `#[unique]` on a field indicates that the field's value must be unique
/// (perhaps implemented as the SQL UNIQUE constraint by some backends).
/// * `[default]` should be used on fields added by later migrations to avoid errors on existing objects.
Expand All @@ -42,9 +38,8 @@ mod filter;
/// #[model]
/// #[table = "posts"]
/// pub struct Post {
/// #[auto]
/// #[pk] // unnecessary if identifier were named id instead
/// pub identifier: i32,
/// pub identifier: AutoPk<i32>,
/// pub title: String,
/// pub content: String,
/// #[default = false]
Expand Down
Loading