tink_sql icon indicating copy to clipboard operation
tink_sql copied to clipboard

Extendable Table class?

Open kevinresol opened this issue 8 years ago • 3 comments

I found myself writing the same query such as db.user.where(user.id == id).first() again and again. I wonder if it is possible to extend the generated table and add methods like db.user.get(id)

kevinresol avatar May 26 '17 06:05 kevinresol

Static extensions should work ;)

But yeah, let's see what we can do.

back2dos avatar May 26 '17 06:05 back2dos

Static extensions should work ;)

I wonder what is the type of the generated table? Is it tink.sql.Table<User>?

kevinresol avatar May 26 '17 07:05 kevinresol

Ok I figured it out:


class UserTableTools {
	public static function get(table:Table<{user:User}>, id:Id<User>)
		return table.where(user.id == id).first();
}

kevinresol avatar May 26 '17 07:05 kevinresol