parseJoinClauses function

List<Join> parseJoinClauses(
  1. String joinClauses
)

Parse the JOIN clauses of a SQL SELECT statement.

Implementation

List<Join> parseJoinClauses(String joinClauses) => joinClauses.isEmpty
    ? []
    : RegExp(
        r'\b(INNER\s+JOIN|LEFT\s+JOIN|RIGHT\s+JOIN|FULL\s+JOIN|JOIN)\s+(\w+)\s+ON\s+(.*?)(?=\s+(?:INNER\s+JOIN|LEFT\s+JOIN|RIGHT\s+JOIN|FULL\s+JOIN|JOIN)\b|$)',
        caseSensitive: false,
        dotAll: true,
      )
        .allMatches(joinClauses)
        .map(
          (match) => Join(
            type: _parseJoinType(match.group(1)!.split(RegExp(r'\s+'))[0]),
            table: match.group(2)!,
            on: parseWhereClause(match.group(3)!.trim()),
          ),
        )
        .toList();