Compare commits
No commits in common. "9d0cc13b65a54852aa138bd0e693ca61cc8bd64a" and "28bef7ef42a90a773efec319ecc3e39756939f10" have entirely different histories.
9d0cc13b65
...
28bef7ef42
4 changed files with 6 additions and 40 deletions
|
@ -14,36 +14,6 @@ pub fn Insertable(comptime ValueType: type) type {
|
|||
};
|
||||
}
|
||||
|
||||
/// Build an insertable structure type from a normal structure.
|
||||
pub fn InsertableStruct(comptime StructType: type) type {
|
||||
// Get type info of the given structure.
|
||||
const typeInfo = @typeInfo(StructType);
|
||||
|
||||
// Initialize fields of the insertable struct.
|
||||
var newFields: [typeInfo.Struct.fields.len]std.builtin.Type.StructField = undefined;
|
||||
for (typeInfo.Struct.fields, &newFields) |field, *newField| {
|
||||
// Create a new field for each field of the given struct.
|
||||
const newFieldType = Insertable(field.type);
|
||||
newField.* = std.builtin.Type.StructField{
|
||||
.name = field.name,
|
||||
.type = newFieldType,
|
||||
.default_value = null,
|
||||
.is_comptime = false,
|
||||
.alignment = @alignOf(newFieldType),
|
||||
};
|
||||
}
|
||||
|
||||
// Return the insertable structure type.
|
||||
return @Type(std.builtin.Type{
|
||||
.Struct = .{
|
||||
.layout = .auto,
|
||||
.decls = &[0]std.builtin.Type.Declaration{},
|
||||
.fields = &newFields,
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/// Repository insert query configuration structure.
|
||||
pub fn RepositoryInsertConfiguration(comptime InsertShape: type) type {
|
||||
return struct {
|
||||
|
|
|
@ -50,15 +50,12 @@ pub fn ModelKeyType(comptime Model: type, comptime TableShape: type, comptime co
|
|||
var fieldName: [keyName.len:0]u8 = undefined;
|
||||
@memcpy(fieldName[0..keyName.len], keyName);
|
||||
|
||||
// Get current field type.
|
||||
const fieldType = std.meta.fields(TableShape)[std.meta.fieldIndex(TableShape, keyName).?].type;
|
||||
|
||||
field.* = .{
|
||||
.name = &fieldName,
|
||||
.type = fieldType,
|
||||
.type = std.meta.fields(TableShape)[std.meta.fieldIndex(TableShape, keyName).?].type,
|
||||
.default_value = null,
|
||||
.is_comptime = false,
|
||||
.alignment = @alignOf(fieldType),
|
||||
.alignment = 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ pub const RepositoryConfiguration = repository.RepositoryConfiguration;
|
|||
pub const RepositoryResult = repository.RepositoryResult;
|
||||
|
||||
pub const Insertable = insert.Insertable;
|
||||
pub const InsertableStruct = insert.InsertableStruct;
|
||||
|
||||
pub const QueryParameter = _sql.QueryParameter;
|
||||
pub const SqlParams = _sql.SqlParams;
|
||||
|
|
|
@ -59,10 +59,10 @@ const CompositeModelRepository = zrm.Repository(CompositeModel, CompositeModelTa
|
|||
.table = "composite_models",
|
||||
|
||||
// Insert shape used by default for inserts in the repository.
|
||||
.insertShape = zrm.InsertableStruct(struct {
|
||||
secondcol: []const u8,
|
||||
label: []const u8,
|
||||
}),
|
||||
.insertShape = struct {
|
||||
secondcol: zrm.Insertable([]const u8),
|
||||
label: zrm.Insertable([]const u8),
|
||||
},
|
||||
|
||||
.key = &[_][]const u8{"firstcol", "secondcol"},
|
||||
|
||||
|
|
Loading…
Reference in a new issue