Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

an orm for rust

License

NotificationsYou must be signed in to change notification settings

ivanceras/rustorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

rustorm

Rustorm

Financial Contributors on Open CollectiveLatest VersionBuild StatusMIT licensed

Rustorm is an SQL-centered ORM with focus on ease of use on conversion of database types totheir appropriate rust type.

Selecting records

use rustorm::{DbError,FromDao,Pool,ToColumnNames,ToTableName,};#[derive(Debug,FromDao,ToColumnNames,ToTableName)]structActor{actor_id:i32,first_name:String,}#[cfg(any(feature="with-postgres", feature ="with-sqlite"))]fnmain(){letmut pool =Pool::new();#[cfg(feature ="with-sqlite")]let db_url ="sqlite://sakila.db";#[cfg(feature ="with-postgres")]let db_url ="postgres://postgres:p0stgr3s@localhost/sakila";let em = pool.em(db_url).unwrap();let sql ="SELECT * FROM actor LIMIT 10";let actors:Result<Vec<Actor>,DbError> =        em.execute_sql_with_return(sql,&[]);println!("Actor: {:#?}", actors);let actors = actors.unwrap();assert_eq!(actors.len(),10);for actorin actors{println!("actor: {:?}", actor);}}#[cfg(feature="with-mysql")]fnmain(){println!("see examples for mysql usage, mysql has a little difference in the api");}

Inserting and displaying the inserted records

use chrono::{    offset::Utc,DateTime,NaiveDate,};use rustorm::{DbError,FromDao,Pool,TableName,ToColumnNames,ToDao,ToTableName,};#[cfg(any(feature="with-postgres", feature ="with-sqlite"))]fnmain(){mod for_insert{usesuper::*;#[derive(Debug,PartialEq,ToDao,ToColumnNames,ToTableName)]pubstructActor{pubfirst_name:String,publast_name:String,}}mod for_retrieve{usesuper::*;#[derive(Debug,FromDao,ToColumnNames,ToTableName)]pubstructActor{pubactor_id:i32,pubfirst_name:String,publast_name:String,publast_update:DateTime<Utc>,}}letmut pool =Pool::new();#[cfg(feature ="with-sqlite")]let db_url ="sqlite://sakila.db";#[cfg(feature ="with-postgres")]let db_url ="postgres://postgres:p0stgr3s@localhost/sakila";let em = pool.em(db_url).unwrap();let tom_cruise = for_insert::Actor{first_name:"TOM".into(),last_name:"CRUISE".to_string(),};let tom_hanks = for_insert::Actor{first_name:"TOM".into(),last_name:"HANKS".to_string(),};let actors:Result<Vec<for_retrieve::Actor>,DbError> =        em.insert(&[&tom_cruise,&tom_hanks]);println!("Actor: {:#?}", actors);assert!(actors.is_ok());let actors = actors.unwrap();let today =Utc::now().date();assert_eq!(tom_cruise.first_name, actors[0].first_name);assert_eq!(tom_cruise.last_name, actors[0].last_name);assert_eq!(today, actors[0].last_update.date());assert_eq!(tom_hanks.first_name, actors[1].first_name);assert_eq!(tom_hanks.last_name, actors[1].last_name);assert_eq!(today, actors[1].last_update.date());}#[cfg(feature="with-mysql")]fnmain(){println!("see examples for mysql usage, mysql has a little difference in the api");}

Rustorm is wholly used bydiwata

License: MIT

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

About

an orm for rust

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    [8]ページ先頭

    ©2009-2025 Movatter.jp