3 ms·
I guess I don't see how generics would help you reduce the number of insert/update functions. The basic problem of an ORM is to map struct fields to columns; I
by weberc2 9y ago
I guess I don't see how generics would help you reduce the number of insert/update functions. The basic problem of an ORM is to map struct fields to columns; I don't see how generics would help you here. Can you write the generic pseudocode you want to write?
- rmrfrmrf 9y agoI would guess something like: class Collection<T implements Entity> { void insert(T entity) { String vals = entity.props.map(escapeSql).join(","); String qs = entity.props.map(x => "?").join(","); PreparedStatement p = db.prepare("insert into %s (%s) values (%s);", this.tableName, qs, vals); db.submit(p); } }
- weberc2 9y agoGo supports that today. Slice is a generic collection. Map will need to become for loops, but that's minor.