add scope to id
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import Generator
|
||||
import jsonlines
|
||||
from aws_lambda_powertools.shared.json_encoder import Encoder
|
||||
from layercake.dynamodb import deserialize
|
||||
from layercake.strutils import md5_hash
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
@@ -42,7 +43,12 @@ if __name__ == '__main__':
|
||||
with sqlite3.connect('mydatabase.db') as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
'CREATE TABLE IF NOT EXISTS %s (pk TEXT, sk TEXT, json JSON)'
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS %s (
|
||||
_id TEXT PRIMARY KEY,
|
||||
json JSON NOT NULL
|
||||
)
|
||||
"""
|
||||
% table_name
|
||||
)
|
||||
|
||||
@@ -50,12 +56,19 @@ if __name__ == '__main__':
|
||||
readlines(input_dirpath),
|
||||
desc=f'⏳ Inserting into table {table_name}',
|
||||
):
|
||||
_id = md5_hash(
|
||||
str(
|
||||
{
|
||||
'id': record['id'],
|
||||
'sk': record['sk'],
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO %s (pk, sk, json) VALUES (:pk, :sk, :json)'
|
||||
% table_name,
|
||||
'INSERT INTO %s (_id, json) VALUES (:_id, :json)' % table_name,
|
||||
{
|
||||
'pk': record['id'],
|
||||
'sk': record['sk'],
|
||||
'_id': _id,
|
||||
'json': record,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user