docs.rs failed to build rustorm-0.0.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
rustorm-0.20.0
rustorm
A Work in Progress rust ORM library for Postgresql
A fork of my previous, very simple ORM which was written in java
Dependency
- rust-postgres
Features
- intelligent model code generation (The only functional part for now)
- Can figure out linker tables, then build 1:M relation with the tables on the generated code
- Can figure out extension tables, which is just 1:1 relation with another table
To see it in action:
Put the sample database in your local postgresql installation
Alternatively, you cam
Look at the code ./examples/generate_model_code.rs
This will be the code to generate the model code based on the table schema and relationships to other tables.
///generate_model_code.rs
extern crate rustorm;
use Postgres;
use codegen;
use Config;
Product table as an example
This is an example table product
in schema bazaar
(./scripts/bazaar_v6_dump_schema.sql)
-- Inherited from table system.record: organization_id uuid, -- @Value(users.user_id) , which means the value will be set with the users.user_id value...
-- Inherited from table system.record: client_id uuid, -- @Value(users.client_id) The client_id of the user creating this records
-- Inherited from table system.record: created timestamp with time zone NOT NULL DEFAULT now(),
-- Inherited from table system.record: created_by uuid, -- @Value(users.user_id)
-- Inherited from table system.record: updated timestamp with time zone NOT NULL DEFAULT now(),
-- Inherited from table system.record: updated_by uuid, -- @Value(users.user_id)
-- Inherited from table system.record: priority numeric,
-- Inherited from table system.record: name character varying, -- This is @Required it has @DisplayLength(50) - 50 character in display length a @MinLength(1) and @MaxLength(100) - Do not go over 100 characters or else the system will throw a ValueTooLong exception...
-- Inherited from table system.record: description character varying, -- @DisplayLength(100) When building a UI for this field...
-- Inherited from table system.record: help text,
-- Inherited from table system.record: active boolean NOT NULL DEFAULT true, -- @Active
product_id uuid NOT NULL DEFAULT uuid_generate_v4 ,
parent_product_id uuid,
is_service boolean DEFAULT false,
price numeric,
use_parent_price boolean DEFAULT false,
unit character varying,
tags json,
info json, -- {color:"red",...
seq_no integer, -- @Sequence can be used to do alternate ordering of the values, when alphetical or time can not be used
upfront_fee numeric DEFAULT 0.00, -- Applicable to services, usually services has an upfront fee
barcode character varying, -- barcode if scanning the product, conflict can happen, expect to return matching list of products using the barcode
owner_id uuid, -- Whom this product belongs, since created_by can be someone else create the product list in behalf of the owner of the product
currency_id uuid,
CONSTRAINT product_pkey PRIMARY KEY (product_id),
CONSTRAINT product_currency_id_fkey FOREIGN KEY (currency_id)
REFERENCES payment.currency (currency_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT product_user_id_fkey FOREIGN KEY (owner_id)
REFERENCES bazaar.users (user_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED
)
INHERITS (system.record)
(
Look at the file ./examples/gen/bazaar/product.rs
The generated rust code should look like
///
/// This will be exposed as an @Api, including @Table(users, category, product_availability, photo)
///
Take notice of these last members of the struct here
/// has one, extension table
pub product_availability:,
/// has many, indirect referring table, derived from linker table: product_category
pub category:,
/// has many, indirect referring table, derived from linker table: product_photo
pub photo:,
/// has many, indirect referring table, derived from linker table: product_review
pub review:,
- The code generator can figure out that product_availability is just an extension table of the product table.
- It also knows that product:categories has 1:M relationship hinted by the linker table product_category, and so with the Photos and Reviews.
- The
created
column has a data typeDateTime<UTC>
, since it is not nullable, while nullable columns such ascreated_by
will be wrapped withOption<Uuid>
,
I have the generated model code, Now what?
use Product;
// this is the generated module, generated by generate_model_code example
)
##Documentation docs
##Roadmap
- Implement all the features in ivanceras/orm
- Automatic conversion of Row to objects (of the generated model)
- Automatic conversion of HashMap to objects
- Implement the declarative Query API
- become a full blown ORM for rust
- Support for sqlite
For Updates
Follow me on twitter: @ivanceras