Database mapping and automated code generation with template