You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 12, 2023. It is now read-only.
zorm is not your traditional ORM tool. Unlike other ORMs, zorm is designed to provide types for
making object-relational mapping within your scripts simple and not reliant on database table
paradigms.
In zorm, objects are cast on manually defined fields that can be compared:
Object mapping
conststd=@import("std");
// In this example, we'll be mapping our object from JSON.// For this very specific use case, zorm will handle assuming types to be tight and memory-bound.constdumb_payload=\\{\\ "foo": "hello, world",\\ "bar": 420\\}
;
constzorm=@import("zorm");
// Objects are defined as a sort of "factory method." The inner argument is a comptime-known// anonymous struct literal containing fields.constFoo=zorm.Object(.{
// (comptime T: type, data: ?FieldMetadata)// Fields can have a name, description and default value.zorm.Field(?[]constu8, .{ .name="foo", .default=undefined }),
zorm.Field(usize, .{ .name="bar" })
});
pubfnmain() !void {
// With an object defined, we can now generate our own from our payload.// (comptime T: type, data: anytype)constmyFoo: zorm.Object=tryzorm.create(Foo, .{ .JsonString=dumb_payload });
// Accessing data is now done through the newly created object.std.debug.print("{any}\n", .{myFoo.get("foo")});
}
Using datatypes
zorm provides you a set of datatypes. An example of a datatype is Date:
pubfnmain() !void {
// We can build a date from a string, useful for defaults.constdate=tryzorm.Date.fromString("2002-07-23", .@"YYYY-MM-DD");
// This is an ISO 8601 format, which zorm will intelligently determineconstpayload=\\{\\ "date": "1999-12-31"\\}
;
constNewTable=tryzorm.create(
zorm.Object(.{
// Default values must either be undefined or part of the type specified in the field,// as expected when working with structs.zorm.Field(?zorm.Date, .{ .name="date", .default=date })
}),
.{ .JsonString=payload }
);
// 1999 will be returned instead of 2002.std.debug.print("{?}\n", .{NewTable.get("date").f_type.year});
}
Building
zorm runs on 0.10.0-dev and higher versions of Zig.
It is recommended to install and build from source: