Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for declaring DynamoDB table names using @TableName annotation #1152

Open
hardikSinghBehl opened this issue May 14, 2024 · 2 comments

Comments

@hardikSinghBehl
Copy link

hardikSinghBehl commented May 14, 2024

Type: Feature

Describe the solution you'd like
Similar to JPA's @Table annotation that provides the ability to declare table names in the entity class itself. I propose a similar solution of creating a custom annotation @TableName with a single attribute name:

@Target(TYPE)
@Retention(RUNTIME)
public @interface TableName {
    String name() default "";
}

This optional annotation when present in the class, takes precedence over the default snake_case name resolver in the DefaultDynamoDbTableNameResolver class.

@DynamoDbBean
@TableName(name = "MedicalRecords") // plural or whatever is needed
public class MedicalRecord {
    // class implementation
}
public class DefaultDynamoDbTableNameResolver implements DynamoDbTableNameResolver {

        // existing class implementation
        
	@Override
	public String resolve(Class clazz) {
                // existing method implementation
                 
                TableName tableName = clazz.getAnnotation(TableName.class);
                if (tableName != null && StringUtils.hasText(tableName.name())) {
                    String name = tableName.name();
                    return prefix.concat(name).concat(suffix);
                }
		
		// existing method implementation
	}

}

This feature would provide flexibility for developers to use custom table names when needed while still maintaining the default snake case behaviour for classes without the annotation. Also, no need to create a custom implementation of DynamoDbTableNameResolver when using this approach.

Additional context
Can submit PR if the feature is approved.

@hardikSinghBehl
Copy link
Author

Hi @MatejNedic, @maciejwalkowiak, @tomazfernandes. Submitting this feature request for evaluation.

@MatejNedic
Copy link
Member

Hey @hardikSinghBehl ,

Since this is simple wrapper I wouldn't go with personally. Let's see what community thinks. If there is support and need for this lets add it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants