matthunz / typed-sql Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Please add relevant unit tests
#[derive(Table)]
struct Task {
id: u64,
description: String,
is_done: bool,
}
#[derive(Queryable)]
struct TaskQuery {
description: String,
is_done: bool,
}
let mounted_query = Task::table().query(TaskQuery::queryable()).to_sql();
SELECT * FROM tasks;
, is possible to define the fields in the final query?SELECT description, is_done FROM tasks;
Excellent approach of this lib, following the concept 'Security by design'.
Thanks.
There's currently a feature gate on line 71 of src/lib.rs
. After cloning this repository locally, I can confirm that removing this line has no effect whatsoever, indicating that it was unnecessary to begin with. By removing this, the crate will compile on stable.
The sqlx repo: https://github.com/launchbadge/sqlx
For example, use the following methods
let users:Vec<User> = User::query(&conn)
.filter(|user| user.id.neq(6).and(user.id.gt(3)))
.order_by(|user| user.name.then(user.id.ascending()))
.limit(5)
.get()
.await?;
The rusqlite repo: rusqlite repo
The style code can be the same way of the issue: #2
To insert the increasing IDs can be useful to be able to get the result of the insertion.
This is a very crude example, but I would like to have an interface similar to:
#[derive(Default, Debug, typed_sql::Table)]
struct SomeStruct {
// It can be represent like NULL if it None.
// ..or it can just be ignored.
id: Option<u64>,
some_useful_data: u128,
}
let insert = SomeStruct::table()
.insert(SomeStruct::default())
.returns(|some_struct| some_struct.id)
.to_sql();
assert_eq!(
insert,
"INSERT into somestruct(some_useful_data) VALUES (0) RETURNING id;"
);
Mysql is used more than postgres.
Hey,
I love this project, and I am very excited to try it out, however I ran into a problem, where the name of my table is different from the struct name (as it is namespaced).
Are you able to change the table name in any way for a struct derived with Table
?
My code looks like this:
#[derive(Table, FromRow, Debug)]
struct Parent {
id: i32,
first_name: String,
last_name: String,
}
In Diesel I believe they allow you to add #[table_name="people_parent"]
to change the name of a table. Do you have a similar feature planned/does it exist?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.