mjovanc / njord Goto Github PK
View Code? Open in Web Editor NEWA lightweight ORM library for Rust ⛵
Home Page: https://njord.rs
License: BSD 3-Clause "New" or "Revised" License
A lightweight ORM library for Rust ⛵
Home Page: https://njord.rs
License: BSD 3-Clause "New" or "Revised" License
Instead of getting back:
Result<Vec<HashMap<String, Value>>>
Getting something similar to:
Result<Vec<Table>>
We need to be able to fix the possibility of storing a vector of structs that derive the Table
procedural macro:
#[derive(Table)]
#[table_name = "orders"]
pub struct Order {
id: usize,
user: User, // one-to-one relationship
products: Vec<Product>, // one-to-many relationship - populates from based on junction table (gets from macro attribute "table_name" and combines them for example, orders_products)
total_cost: f64,
}
As you can see here when we define a field called products
and add a vector of Product
. It will complain about:
- doesn't satisfy `syn::Type: ToString` or `syn::Type: std::fmt::Display`
We need to be able to support this in the njord_derive library.
We need to implement in the procedural macro so that id fields can be used with Option<T>
since we want the user to control if they want to populate the id
field when doing an INSERT
operation. If you want SQlite to handle autoincrement itself, we don't need to add a value to it.
Commands that should exist:
njord migration generate <name>
njord migration run
njord migration rollback
Flags that should exist on njord
:
-v
and --version
-h
and --help
Flags that should exist on njord migration
:
--dry-run
(simulate the migration)--env
(specify development/test/staging/production etc)--dir
(specify target directory for generated migration changes)--to
(rollback to specific version, for example 20191225120000
)--log-level
(standard, debug etc)Examples:
njord setup
njord migration generate <name> --env=development --dry-run
njord migration run --env=production --log-level=debug
njord migration rollback --env=development --to=20191225120000
SELECT, INSERT, UPDATE, and DELETE statements.
We need to add #[primary_key]
or something similar over the field like this:
#[derive(Table)]
#[table_name = "categories"]
pub struct Category {
#[primary_key]
id: usize,
name: String,
}
So when instantiating it, it should be enough to do:
let table_row: User = User {
name: "mjovanc".to_string(),
};
This is important since when doing INSERT
operations when having autoincrement on the id field and not knowing the current id beforehand, and we definitely do not want to query to get that information before...
INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN to combine rows from two or more tables based on a related column between them.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
We want to add the possibility to add junction tables for a MANY-TO-MANY relationship if we define our tables such as:
#[derive(Table, Default)]
struct Posts {
title: String,
description: String,
category: Categories
}
#[derive(Table, Default)]
struct Categories {
name: String,
}
We have a lot of duplicate code that could be used with one or more functions instead.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
Cargo.toml
rusqlite 0.29.0
.github/workflows/master-ci.yml
actions/checkout v3
actions-rs/toolchain v1
.github/workflows/pr-ci.yml
actions/checkout v3
actions-rs/toolchain v1
We need to have method chaining for SELECT since we can have multiple conditions. An example of a use case would be:
sqlite::select(columns).from(table).where(condition);
Would be nice that we can activate features with what database support is needed like this:
njord = { version = "0.1.0", features = ["derive", "sqlite", "mysql", "postgres"] }
Would be great if we could add features like below to not need to include the njord_derive in the dependencies list:
njord = { version = "0.1.0", features = ["derive"] }
Just thinking of creating a custom field type called PrimaryKey
to add to a field for example id
: https://github.com/njord-rs/njord/blob/master/njord/tests/sqlite_test.rs#L15
Some example implementation:
pub struct PrimaryKey<T>(Option<T>);
impl<T> PrimaryKey<T> {
pub fn new(value: Option<T>) -> Self {
PrimaryKey(value)
}
pub fn get(&self) -> Option<&T> {
self.0.as_ref()
}
}
impl<T> Default for PrimaryKey<T> {
fn default() -> Self {
PrimaryKey(None)
}
}
Usage example:
let table_row: User = User {
id: PrimaryKey::default(),
username: "mjovanc".to_string(),
email: "[email protected]".to_string(),
address: "Some Random Address 1".to_string(),
};
When setting it to ::default we are saying that we want the database to increment the id field automatically using autoincrement.
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.