sqlite doesn't respect composite primary keys?

dev
Anton Franzluebbers 2023-04-27 15:27:17 -04:00
parent 6053808218
commit 4a02fa2757
2 changed files with 14 additions and 4 deletions

View File

@ -72,7 +72,7 @@ CREATE TABLE `DataBlock` (
`id` TEXT NOT NULL, `id` TEXT NOT NULL,
-- id of the owner of this file. Ownership is not transferable because ids may collide, -- id of the owner of this file. Ownership is not transferable because ids may collide,
-- but the owner could be null for global scope -- but the owner could be null for global scope
`owner_id` TEXT NOT NULL DEFAULT 'none', `owner_id` TEXT,
`visibility` TEXT CHECK( `visibility` IN ('public','private','unlisted') ) NOT NULL DEFAULT 'public', `visibility` TEXT CHECK( `visibility` IN ('public','private','unlisted') ) NOT NULL DEFAULT 'public',
-- This is an indexable field to filter out different types of datablocks -- This is an indexable field to filter out different types of datablocks
`category` TEXT, `category` TEXT,

View File

@ -264,9 +264,19 @@ def set_data(request: fastapi.Request, data: dict, key: str = None, owner: str =
# add the data to the db # add the data to the db
db.insert(""" db.insert("""
REPLACE INTO `DataBlock` (id, category, modified_by, data, last_modified) REPLACE INTO `DataBlock` (id, owner_id, category, modified_by, data, last_modified)
VALUES(:id, :category, :modified_by, :data, CURRENT_TIMESTAMP); VALUES(:id, :owner_id, :category, :modified_by, :data, CURRENT_TIMESTAMP);
""", {"id": key, "category": category, "modified_by": modified_by, "data": json.dumps(data)}) """, {"id": key, "owner_id": owner, "category": category, "modified_by": modified_by, "data": json.dumps(data)})
# # add the data to the db
# db.insert("""
# REPLACE INTO `DataBlock` SET
# category = :category,
# modified_by = :modified_by,
# data = :data,
# last_modified = CURRENT_TIMESTAMP
# WHERE id=:id AND owner_id = :owner_id;
# """, {"id": key, "category": category, "modified_by": modified_by, "owner_id": owner, "data": json.dumps(data)})
return {'key': key} return {'key': key}