Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/execute_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from railib import api, config, show


def run(database: str, engine: str, command: str, readonly: bool, profile: str):
def run(database: str, engine: str, command: str, language: str, readonly: bool, profile: str):
cfg = config.read(profile=profile)
ctx = api.Context(**cfg)
rsp = api.exec_async(ctx, database, engine, command, readonly=readonly)
rsp = api.exec_async(ctx, database, engine, command, language, readonly=readonly)
print(rsp)
show.results(rsp)

Expand All @@ -30,6 +30,7 @@ def run(database: str, engine: str, command: str, readonly: bool, profile: str):
p.add_argument("database", type=str, help="database name")
p.add_argument("engine", type=str, help="engine name")
p.add_argument("command", type=str, help="rel source string")
p.add_argument("--language", type=str, help="query language")
p.add_argument(
"--readonly",
action="store_true",
Expand All @@ -39,6 +40,6 @@ def run(database: str, engine: str, command: str, readonly: bool, profile: str):
p.add_argument("-p", "--profile", type=str, default="default", help="profile name")
args = p.parse_args()
try:
run(args.database, args.engine, args.command, args.readonly, args.profile)
run(args.database, args.engine, args.command, args.language, args.readonly, args.profile)
except HTTPError as e:
show.http_error(e)
6 changes: 4 additions & 2 deletions railib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,10 @@ def data(self):
result["engine_name"] = self.engine
return result

def run(self, ctx: Context, command: str, inputs: dict = None) -> Union[dict, list]:
def run(self, ctx: Context, command: str, language: str, inputs: dict = None) -> Union[dict, list]:
data = self.data
data["query"] = command
data["language"] = language
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we use rel vs sql or emtpy vs sql ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can pass either rel, sql, or an empty string that will get defaulted to rel in the service

if inputs is not None:
inputs = [_query_action_input(k, v) for k, v in inputs.items()]
data["v1_inputs"] = inputs
Expand Down Expand Up @@ -860,11 +861,12 @@ def exec_async(
database: str,
engine: str,
command: str,
language: str = "",
readonly: bool = True,
inputs: dict = None,
) -> TransactionAsyncResponse:
tx = TransactionAsync(database, engine, readonly=readonly)
rsp = tx.run(ctx, command, inputs=inputs)
rsp = tx.run(ctx, command, language=language, inputs=inputs)

if isinstance(rsp, dict):
return TransactionAsyncResponse(rsp, None, None, None)
Expand Down