mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-08-18 19:30:10 +02:00
* WIP converted all sqlite models into prisma calls * modify db setup and fix ApiKey model calls in admin.js * renaming function params to be consistent * converted adminEndpoints to utilize prisma orm * converted chatEndpoints to utilize prisma orm * converted inviteEndpoints to utilize prisma orm * converted systemEndpoints to utilize prisma orm * converted workspaceEndpoints to utilize prisma orm * converting sql queries to prisma calls * fixed default param bug for orderBy and limit * fixed typo for workspace chats * fixed order of deletion to account for sql relations * fix invite CRUD and workspace management CRUD * fixed CRUD for api keys * created prisma setup scripts/docs for understanding how to use prisma * prisma dependency change * removing unneeded console.logs * removing unneeded sql escape function * linting and creating migration script * migration from depreciated sqlite script update * removing unneeded migrations in prisma folder * create backup of old sqlite db and use transactions to ensure all operations complete successfully * adding migrations to gitignore * updated PRISMA.md docs for info on how to use sqlite migration script * comment changes * adding back migrations folder to repo * Reviewing SQL and prisma integraiton on fresh repo * update inline key replacement * ensure migration script executes and maps foreign_keys regardless of db ordering * run migration endpoint * support new prisma backend * bump version * change migration call --------- Co-authored-by: timothycarambat <rambat1010@gmail.com>
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
const prisma = require("../utils/prisma");
|
|
|
|
const WelcomeMessages = {
|
|
get: async function (clause = {}) {
|
|
try {
|
|
const message = await prisma.welcome_messages.findFirst({
|
|
where: clause,
|
|
});
|
|
return message || null;
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return null;
|
|
}
|
|
},
|
|
|
|
where: async function (clause = {}, limit) {
|
|
try {
|
|
const messages = await prisma.welcome_messages.findMany({
|
|
where: clause,
|
|
take: limit || undefined,
|
|
});
|
|
return messages;
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return [];
|
|
}
|
|
},
|
|
|
|
saveAll: async function (messages) {
|
|
try {
|
|
await prisma.welcome_messages.deleteMany({}); // Delete all existing messages
|
|
|
|
// Create new messages
|
|
for (const [index, message] of messages.entries()) {
|
|
await prisma.welcome_messages.create({
|
|
data: {
|
|
user: message.user,
|
|
response: message.response,
|
|
orderIndex: index,
|
|
},
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error("Failed to save all messages", error.message);
|
|
}
|
|
},
|
|
|
|
getMessages: async function () {
|
|
try {
|
|
const messages = await prisma.welcome_messages.findMany({
|
|
orderBy: { orderIndex: "asc" },
|
|
select: { user: true, response: true },
|
|
});
|
|
return messages;
|
|
} catch (error) {
|
|
console.error("Failed to get all messages", error.message);
|
|
return [];
|
|
}
|
|
},
|
|
};
|
|
|
|
module.exports.WelcomeMessages = WelcomeMessages;
|