authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-08 18:04:01 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-08 18:04:01 -07:00
log66ae64bdb507e6fdd066683c331e3aaa8350a8c7
tree9a0d81f8acf758e641a955c1a9c91fdec69caca8
parentc6deb0614b63a9c2f983887cc5cec917d14393d2
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

sqlite: handle default values now that nameForType handles 'not null'


1 files changed, 23 insertions(+), 1 deletions(-)

src/sqlite3.zig+23-1
......@@ -111,7 +111,7 @@ pub fn nameForType(T: type) []const u8 {
111111 if (@typeInfo(T) == .optional) {
112112 return nameForType2(@typeInfo(T).optional.child);
113113 }
114 return nameForType2(T) ++ " not null";
114 return nameForType2(T) ++ " not null default (" ++ defaultForType(T) ++ ")";
115115}
116116
117117pub fn nameForType2(T: type) []const u8 {
......@@ -137,6 +137,28 @@ pub fn nameForType2(T: type) []const u8 {
137137 @compileError(@typeName(T)); // TODO
138138}
139139
140pub fn defaultForType(T: type) []const u8 {
141 const info = @typeInfo(T);
142 if (info == .bool) {
143 return "false";
144 }
145 if (info == .@"struct") {
146 const sinfo = info.@"struct";
147 if (@hasDecl(T, "BaseType")) return defaultForType(T.BaseType);
148 if (sinfo.layout == .@"packed") return defaultForType(sinfo.backing_integer.?);
149 }
150 if (comptime extras.isZigString(T)) {
151 return "''";
152 }
153 if (info == .int) {
154 return "0";
155 }
156 if (info == .@"enum") {
157 return defaultForType(T.BaseType);
158 }
159 @compileError(@typeName(T)); // TODO
160}
161
140162pub const Pragma = struct {
141163 pub const TableInfo = struct {
142164 cid: u16,