question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom SQL support

See original GitHub issue

To allow odd requirements, or using special SQL syntax that is not yet supported (or may never be) by Tortoise ORM we should provide a simple, clean, custom SQL interface.

How do we identify the connection?

Is Tortoise.get_connection("models") adequate?

Currently the connection used execute() function accepts RAW SQL, and returns data in a RAW format (dependant on the DB driver)

These functions are used internally by the ORM itself. We should privatise these, and provide standard public functions that have a well-defined interface.

How do we format parameters?

Since parametrized queries are all handled very differently for each DB we support, we should do an intermediate representation and support that. Possibly just adapt the same {field} format that SQLAlchemy ORM has and map those to the right parameter format for the local db?

How do we handle parameters?

Named parameters only. For single, should it be kwarg based: execute("<SQL>", ...) or dict based: execute("<SQL>", {...}) ? For bulk operations we can only accept a list of dicts each containing I would make it ALWAYS just accept a dict

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gdmoorecommented, Mar 23, 2020

It’s definitely a “last resort” feature. For example Pony-orm doesn’t support Python enums. You can write a converter to create the model initially, but every query you write will be broken since it doesn’t know how to serialize an enum. In a previous project we worked around it by using raw_sql for only the portion of the query involving the enum.

None of that applies to tortoise but I’m sure there will be the occasional weird use case someone has.

Supporting it in both F and Q objects would probably be great.

1reaction
lntuitioncommented, Mar 23, 2020

Yeah. I agree that it have to be limited use. I think expand and refactor current F and Q to support custom SQL is good choice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect to a Custom SQL Query - Tableau Help
Supported queries. Catalog supports custom SQL queries that meet the ANSI SQL-2003 standard, with three known exceptions: Time zone expressions; Multiset ...
Read more >
6 Ways to Offer Custom SQL Support in Your Product - Resmo
There are multiple ways of providing SQL in your product, each having its own pros and cons. Here are 6 ways to do...
Read more >
Custom SQL Queries - Logi Analytics
Custom SQL Queries. Applicable only to SQL-based connectors, a data source using a connector that supports custom SQL queries can use an SQL...
Read more >
How to set up custom SQL query with the MS SQL agent? - IBM
To created custom SQL queries you must edit KoqCusSQL.properties file ... It supports 5 STRING type columns, 5 Integer Type columns and 4...
Read more >
Working with Custom SQL in Tableau: 5 Easy Steps - Learn
Tableau supports connectivity to several data sources like SQL Server which helps to load the desired data. These may not be optimized in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found