0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dataset(PythonのORマッパー)で実行したSQLを取得する

Last updated at Posted at 2020-09-30

概要

dataset(PythonのORマッパー)で実行したSQLを取得する。

dataset: 1.3.2
mysqlclient: 1.4.6

dataset公式

実装

前提

事前に↓してあること。

db = dataset.connect(url)

query()する場合

result = db.query("select * from test1")

result.result_proxy.context.statement
> 'select * from test1'

find()する場合

table: dataset.Table = db['test1']
result = table.find()

result.result_proxy.context.statement
> 'SELECT test1.id \nFROM test1 \n LIMIT %s, 18446744073709551615'

もしくは、

result = iter(db['test1'])

result.result_proxy.context.statement
> 'SELECT test1.id \nFROM test1 \n LIMIT %s, 18446744073709551615'

備考

query()の場合もfind()の場合も、dataset.util.ResultIterが返ってくる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?