orm: fix time struct in sql stmt (#12298)
							parent
							
								
									5e4594a121
								
							
						
					
					
						commit
						d33f7d12f7
					
				| 
						 | 
					@ -10,6 +10,7 @@ struct Module {
 | 
				
			||||||
	nr_downloads int
 | 
						nr_downloads int
 | 
				
			||||||
	test_id      u64
 | 
						test_id      u64
 | 
				
			||||||
	user         User
 | 
						user         User
 | 
				
			||||||
 | 
						created      time.Time
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[table: 'userlist']
 | 
					[table: 'userlist']
 | 
				
			||||||
| 
						 | 
					@ -330,4 +331,16 @@ fn test_orm_sqlite() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assert test_id_mod.test_id == 11
 | 
						assert test_id_mod.test_id == 11
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						t := time.now()
 | 
				
			||||||
 | 
						sql db {
 | 
				
			||||||
 | 
							update Module set created = t where id == 1
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						updated_time_mod := sql db {
 | 
				
			||||||
 | 
							select from Module where id == 1
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// NB: usually updated_time_mod.created != t, because t has
 | 
				
			||||||
 | 
						// its microseconds set, while the value retrieved from the DB
 | 
				
			||||||
 | 
						// has them zeroed, because the db field resolution is seconds.
 | 
				
			||||||
 | 
						assert updated_time_mod.created.format_ss() == t.format_ss()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7893,7 +7893,7 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sym := c.table.get_type_symbol(field.typ)
 | 
						sym := c.table.get_type_symbol(field.typ)
 | 
				
			||||||
	if sym.kind == .struct_ {
 | 
						if sym.kind == .struct_ && sym.name != 'time.Time' {
 | 
				
			||||||
		name = '${name}_id'
 | 
							name = '${name}_id'
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return name
 | 
						return name
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue