Skip to content

Support trimming whitespace from table and alias names #39

@adrianbrowning

Description

@adrianbrowning

Description

When users provide table names or aliases with leading/trailing whitespace (e.g., "User " or "Post p"), the library should automatically trim the whitespace to prevent SQL generation issues.

Current Behavior

Table and alias names are used as-is without trimming, which can lead to:

  • Malformed SQL queries
  • Unexpected spaces in table aliases
  • Type inference issues

Expected Behavior

The library should automatically trim whitespace from:

  • Table names in $from() calls
  • Table names in join methods (.join(), .joinUnsafeTypeEnforced(), .joinUnsafeIgnoreType())
  • Alias names (both in inline syntax like "User u" and object syntax)

Examples

// These should all work identically:
prisma.$from("User")
prisma.$from("User ")
prisma.$from(" User")

// Join with trailing space:
prisma.$from("User u")
  .join("Post p ", "authorId", "u.id")

// Object syntax with spaces:
prisma.$from("User ")
  .join({table: "Post ", src: "authorId", on: "User.id", alias: "p "})

Implementation Notes

  • Add Trim type helper for compile-time trimming
  • Add runtime .trim() calls when parsing table/alias strings
  • Ensure both positional and object syntax support trimming
  • Apply to all join methods consistently

Related

This was discovered during the implementation of inline alias syntax (e.g., "User u" instead of separate alias parameter).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions