dorm 0.4.0
A D ORM.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
DORM
A sophisticated D ORM using rorm-lib as a backend.
Works standalone using multi-threading or with vibe-core.
The following databases are currently supported:
- SQLite 3
- MariaDB 10.5 - 10.9
- Postgres 11 - 15
Documentation
Take a look at rorm-orm/docs or just use the deployed documentation: rorm.rs.
Auto-generated source code documentation is available on https://dorm.dpldocs.info/.
Installation
dub add dorm
When first compiling, DORM will automatically download pre-compiled library binaries into the package location when it hasn't been downloaded yet. You can also manually put the librorm.a
(Posix) or rorm.lib
(Windows) file into the DUB package to not make it download anything.
You can use dub run dorm
to run the supporting CLI tool, which will be downloaded at the same time. rorm-cli
is used for creating migrations, which you check-in into your project source and to apply migrations both on development machines as well as on production machines.
Example
For a more detailed walkthrough see rorm.rs
module models;
import dorm.design;
mixin RegisterModels;
class User : Model
{
@Id long id;
@maxLength(255)
string username;
@maxLength(255)
string password;
@autoCreateTime
SysTime createdAt;
@columnName("admin")
bool isAdmin;
@constructValue!(() => Clock.currTime + 24.hours)
SysTime tempPasswordTime;
}
import models;
import faked, std.datetime.systime, std.random, std.stdio;
import dorm.api.db;
mixin SetupDormRuntime;
void main() {
@DormPatch!User
struct UserSelection {
long id;
string username;
SysTime createdAt;
}
auto appConfig = parseTomlConfig!BareConfiguration("database.toml");
auto db = DormDB(appConfig.database);
auto f = new Faker_de(uniform!int);
foreach (i; 0 .. 2) {
@DormPatch!User
struct UserInsert {
string username;
string password;
bool isAdmin;
}
UserInsert user;
user.username = f.nameName;
user.password = "123456";
db.insert(user);
}
auto oldestUsers = db.select!UserSelection
.condition(u => u.not.isAdmin)
.orderBy(u => u.createdAt.asc)
.limit(5)
.stream();
writeln("Oldest 5 Users:");
foreach (i, user; oldestUsers) {
writefln!"#%d %s\tcreated at %s"(i + 1, user.username, user.createdAt);
// delete first user
if (i == 0)
db.remove(user);
}
}
For a more detailed walkthrough see rorm.rs
Contribution
Before contribution, see the development guidelines.
- 0.4.0 released a year ago
- rorm-orm/dorm
- MIT
- Copyright © 2022, WebFreak
- Authors:
- Sub packages:
- dorm:build-models, dorm:init-exec
- Dependencies:
- mir-toml, vibe-core, mir-ion
- Versions:
-
0.4.0 2023-Feb-21 0.3.1 2022-Dec-01 0.3.0 2022-Dec-01 0.2.0 2022-Nov-30 0.1.0 2022-Nov-24 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
88 downloads total
-
- Score:
- 0.0
- Short URL:
- dorm.dub.pm