u
This commit is contained in:
79
src/providers/mssql/queries/modelconversation.js
Normal file
79
src/providers/mssql/queries/modelconversation.js
Normal file
@@ -0,0 +1,79 @@
|
||||
export const MODELCONVERSATION_COLUMNS = `
|
||||
id,
|
||||
companyuser_id,
|
||||
provider,
|
||||
model,
|
||||
created_at,
|
||||
updated_at,
|
||||
state
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANYUSER = `
|
||||
SELECT
|
||||
${MODELCONVERSATION_COLUMNS}
|
||||
FROM modelconversation
|
||||
WHERE companyuser_id = @companyuserId
|
||||
ORDER BY updated_at DESC, id DESC
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANYUSER_AND_ID = `
|
||||
SELECT
|
||||
${MODELCONVERSATION_COLUMNS}
|
||||
FROM modelconversation
|
||||
WHERE id = @id AND companyuser_id = @companyuserId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO modelconversation (
|
||||
companyuser_id,
|
||||
provider,
|
||||
model
|
||||
)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.companyuser_id,
|
||||
INSERTED.provider,
|
||||
INSERTED.model,
|
||||
INSERTED.created_at,
|
||||
INSERTED.updated_at,
|
||||
INSERTED.state
|
||||
VALUES (
|
||||
@companyuserId,
|
||||
@provider,
|
||||
@model
|
||||
)
|
||||
`;
|
||||
|
||||
/** Atomic idle guard + touch: affects 0 rows unless the conversation is idle. */
|
||||
export const TOUCH_IF_IDLE = `
|
||||
UPDATE modelconversation
|
||||
SET updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id AND companyuser_id = @companyuserId AND state = 'idle'
|
||||
`;
|
||||
|
||||
/** Unconditional touch (used when appending assistant/system messages or updating activity). */
|
||||
export const TOUCH = `
|
||||
UPDATE modelconversation
|
||||
SET updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id AND companyuser_id = @companyuserId
|
||||
`;
|
||||
|
||||
/** Updates conversation state ('idle' | 'busy') and touches updated_at. */
|
||||
export const SET_STATE = `
|
||||
UPDATE modelconversation
|
||||
SET state = @state, updated_at = SYSUTCDATETIME()
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.companyuser_id,
|
||||
INSERTED.provider,
|
||||
INSERTED.model,
|
||||
INSERTED.created_at,
|
||||
INSERTED.updated_at,
|
||||
INSERTED.state
|
||||
WHERE id = @id AND companyuser_id = @companyuserId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANYUSER_AND_ID = `
|
||||
DELETE FROM modelconversation
|
||||
WHERE id = @id AND companyuser_id = @companyuserId
|
||||
`;
|
||||
34
src/providers/mssql/queries/modelmessage.js
Normal file
34
src/providers/mssql/queries/modelmessage.js
Normal file
@@ -0,0 +1,34 @@
|
||||
export const MODELMESSAGE_COLUMNS = `
|
||||
id,
|
||||
conversation_id,
|
||||
created_at,
|
||||
role,
|
||||
message
|
||||
`;
|
||||
|
||||
export const LIST_BY_CONVERSATION = `
|
||||
SELECT
|
||||
${MODELMESSAGE_COLUMNS}
|
||||
FROM modelmessage
|
||||
WHERE conversation_id = @conversationId
|
||||
ORDER BY id ASC
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO modelmessage (
|
||||
conversation_id,
|
||||
role,
|
||||
message
|
||||
)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.conversation_id,
|
||||
INSERTED.created_at,
|
||||
INSERTED.role,
|
||||
INSERTED.message
|
||||
VALUES (
|
||||
@conversationId,
|
||||
@role,
|
||||
@message
|
||||
)
|
||||
`;
|
||||
63
src/providers/mssql/queries/modelvfs.js
Normal file
63
src/providers/mssql/queries/modelvfs.js
Normal file
@@ -0,0 +1,63 @@
|
||||
export const MODELVFS_COLUMNS = `
|
||||
id,
|
||||
company_id,
|
||||
name,
|
||||
mime,
|
||||
meta,
|
||||
created_at,
|
||||
updated_at
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
${MODELVFS_COLUMNS},
|
||||
content
|
||||
FROM modelvfs
|
||||
WHERE company_id = @companyId AND name = @name
|
||||
`;
|
||||
|
||||
export const GET_META_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
${MODELVFS_COLUMNS}
|
||||
FROM modelvfs
|
||||
WHERE company_id = @companyId AND name = @name
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
${MODELVFS_COLUMNS}
|
||||
FROM modelvfs
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY name ASC
|
||||
`;
|
||||
|
||||
export const UPSERT = `
|
||||
MERGE modelvfs AS target
|
||||
USING (SELECT @companyId AS company_id, @name AS name) AS src
|
||||
ON target.company_id = src.company_id AND target.name = src.name
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET mime = @mime, content = @content, meta = @meta, updated_at = SYSUTCDATETIME()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (company_id, name, mime, content, meta)
|
||||
VALUES (@companyId, @name, @mime, @content, @meta)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.company_id,
|
||||
INSERTED.name,
|
||||
INSERTED.mime,
|
||||
INSERTED.meta,
|
||||
INSERTED.created_at,
|
||||
INSERTED.updated_at;
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_NAME = `
|
||||
DELETE FROM modelvfs
|
||||
OUTPUT DELETED.id
|
||||
WHERE company_id = @companyId AND name = @name
|
||||
`;
|
||||
|
||||
export const DELETE_ALL_BY_COMPANY = `
|
||||
DELETE FROM modelvfs
|
||||
OUTPUT DELETED.id
|
||||
WHERE company_id = @companyId
|
||||
`;
|
||||
Reference in New Issue
Block a user