|
| 1 | +# DORM |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +A sophisticated D ORM using [rorm-lib](https://github.com/rorm-orm/rorm-lib) as a backend. |
| 6 | + |
| 7 | +Works standalone using multi-threading or with vibe-core. |
| 8 | + |
| 9 | +The following databases are currently supported: |
| 10 | +- SQLite 3 |
| 11 | +- MariaDB 10.5 - 10.9 |
| 12 | +- Postgres 11 - 15 |
| 13 | + |
| 14 | +## Documentation |
| 15 | + |
| 16 | +Take a look at [rorm-orm/docs](https://github.com/rorm-orm/docs) or just use the |
| 17 | +deployed documentation: [rorm.rs](https://rorm.rs). |
| 18 | + |
| 19 | +Auto-generated source code documentation is available on [https://dorm.dpldocs.info/](https://dorm.dpldocs.info/). |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +``` |
| 24 | +dub add dorm |
| 25 | +``` |
| 26 | + |
| 27 | +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. |
| 28 | + |
| 29 | +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. |
| 30 | + |
| 31 | +## Example |
| 32 | + |
| 33 | +For a more detailed walkthrough see [rorm.rs](https://rorm.rs) |
| 34 | + |
| 35 | +```d |
| 36 | +module models; |
| 37 | +
|
| 38 | +import dorm.design; |
| 39 | +
|
| 40 | +mixin RegisterModels; |
| 41 | +
|
| 42 | +class User : Model |
| 43 | +{ |
| 44 | + @Id long id; |
| 45 | +
|
| 46 | + @maxLength(255) |
| 47 | + string username; |
| 48 | +
|
| 49 | + @maxLength(255) |
| 50 | + string password; |
| 51 | +
|
| 52 | + @autoCreateTime |
| 53 | + SysTime createdAt; |
| 54 | +
|
| 55 | + @columnName("admin") |
| 56 | + bool isAdmin; |
| 57 | +
|
| 58 | + @constructValue!(() => Clock.currTime + 24.hours) |
| 59 | + SysTime tempPasswordTime; |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +```d |
| 64 | +import models; |
| 65 | +
|
| 66 | +import faked, std.datetime.systime, std.random, std.stdio; |
| 67 | +
|
| 68 | +import dorm.api.db; |
| 69 | +
|
| 70 | +mixin SetupDormRuntime; |
| 71 | +
|
| 72 | +void main() { |
| 73 | + @DormPatch!User |
| 74 | + struct UserSelection { |
| 75 | + long id; |
| 76 | + string username; |
| 77 | + SysTime createdAt; |
| 78 | + } |
| 79 | +
|
| 80 | + DBConnectOptions options = { |
| 81 | + backend: DBBackend.SQLite, |
| 82 | + name: "database.sqlite3" |
| 83 | + }; |
| 84 | + auto db = DormDB(options); |
| 85 | +
|
| 86 | + auto f = new Faker_de(uniform!int); |
| 87 | +
|
| 88 | + foreach (i; 0 .. 2) { |
| 89 | + @DormPatch!User |
| 90 | + struct UserInsert { |
| 91 | + string username; |
| 92 | + string password; |
| 93 | + bool isAdmin; |
| 94 | + } |
| 95 | +
|
| 96 | + UserInsert user; |
| 97 | + user.username = f.nameName; |
| 98 | + user.password = "123456"; |
| 99 | + db.insert(user); |
| 100 | + } |
| 101 | +
|
| 102 | + auto oldestUsers = db.select!UserSelection |
| 103 | + .condition(u => u.not.isAdmin) |
| 104 | + .orderBy(u => u.createdAt.asc) |
| 105 | + .limit(5) |
| 106 | + .stream(); |
| 107 | +
|
| 108 | + writeln("Oldest 5 Users:"); |
| 109 | + foreach (i, user; oldestUsers) { |
| 110 | + writefln!"#%d %s\tcreated at %s"(i + 1, user.username, user.createdAt); |
| 111 | +
|
| 112 | + // delete first user |
| 113 | + if (i == 0) |
| 114 | + db.remove(user); |
| 115 | + } |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +For a more detailed walkthrough see [rorm.rs](https://rorm.rs) |
| 120 | + |
| 121 | +## Contribution |
| 122 | + |
| 123 | +Before contribution, see the [development guidelines](https://rorm.rs/developer/guidelines). |
0 commit comments