-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add query type support for SOQL
- Loading branch information
Showing
17 changed files
with
270 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Utils | ||
module QueryValidator | ||
def self.validate_query(query_type, query) | ||
case query_type.to_sym | ||
when :raw_sql | ||
begin | ||
PgQuery.parse(query) | ||
rescue PgQuery::ParseError => e | ||
raise StandardError, "Query contains invalid SQL syntax: #{e.message}" | ||
end | ||
when :soql | ||
begin | ||
# TODO: SOQL | ||
rescue StandardError => e | ||
raise StandardError, "Query contains invalid SOQL syntax: #{e.message}" | ||
end | ||
else | ||
raise StandardError, "Unsupported query_type" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Utils::QueryValidator do | ||
describe ".validate_query" do | ||
context "with valid SQL query" do | ||
let(:query_type) { :raw_sql } | ||
let(:query) { "SELECT * FROM users;" } | ||
|
||
it "does not raise an error" do | ||
expect { described_class.validate_query(query_type, query) }.not_to raise_error | ||
end | ||
end | ||
|
||
context "with invalid SQL query" do | ||
let(:query_type) { :raw_sql } | ||
let(:query) { "INVALID SQL QUERY;" } | ||
|
||
it "raises a StandardError with error message" do | ||
expect do | ||
described_class.validate_query(query_type, query) | ||
end.to raise_error(StandardError, /contains invalid SQL syntax/) | ||
end | ||
end | ||
|
||
context "with unsupported query type" do | ||
let(:query_type) { :unsupported } | ||
let(:query) { "SELECT * FROM users;" } | ||
|
||
it "raises a StandardError with error message" do | ||
expect do | ||
described_class.validate_query(query_type, query) | ||
end.to raise_error(StandardError, /Unsupported query_type/) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.