LoginSignup
1
2

More than 3 years have passed since last update.

DynamoDBをPythonからSQLっぽく操作する。

Posted at

set up


pip install dql 

code


import dql
import boto3
import os
table_name=os.environ['TABLE_NAME'] # dynamodb


engine = dql.Engine()
c = engine.connect(
    region=os.environ['AWS_DEFAULT_REGION'],
    access_key=os.environ['AWS_ACCESS_KEY_ID'],
    secret_key=os.environ['AWS_SECRET_ACCESS_KEY'],
    host=os.environ['HOST'],
    port=int(os.environ['PORT']),
    is_secure=False
)
print("--scan--")
results = engine.execute(f"SCAN * FROM {table_name} LIMIT 10")
for item in results:
    print(dict(item))

print("--delete--")
results = engine.execute(f"DELETE FROM {table_name} WHERE tm>=1235 and tm<=1236")

print("--scan--")
results = engine.execute(f"SCAN * FROM {table_name} LIMIT 10")
for item in results:
    print(dict(item))

※Selectを利用するためには設定を変更する必要あり。

その他のクエリに関しては下記を参照ください。
https://dql.readthedocs.io/en/latest/topics/queries/index.html

備忘録

DQLドキュメント
https://dql.readthedocs.io/en/latest/ref/dql.engine.html

接続の実態は、dynamo3モジュールのDynamoDBConnectionという物
https://pypi.org/project/dynamo3

動画とDocker-compose

IMAGE ALT TEXT HERE

動画内で説明している通り、Docker-compose環境も作成しました。

1
2
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
1
2