MCPcopy Create free account
hub / github.com/IceClusters/icmysql / FindOrCreate

Function FindOrCreate

src/db/orm/index.js:229–251  ·  view source on GitHub ↗
(index, model, options, callback)

Source from the content-addressed store, hash-verified

227}
228
229async function FindOrCreate(index, model, options, callback) {
230 ScheduleResourceTick(global.resourceName)
231 if (!Config.ORM) return ParseError("You're trying to execute a ORM query without ORM enabled in the config.js.")
232 if (typeof index === "string") {
233 if (typeof options === "function")
234 callback = options;
235 options = model;
236 model = index;
237 index = Config.DefaultORMDB;
238 }
239 if (options == null || options.length == 0) options = {};
240 options.raw = Config.RawData;
241
242 try {
243 const result = await poolsORM[index].models[model].findOrCreate(await ParseOperators(options));
244 if (typeof callback === "function") return callback(result);
245 return result;
246 } catch (e) {
247 ParseError(`Can't find or create with ORM database ${index}, ${e.message}.`);
248 if (typeof callback === "function") return callback(null);
249 return null;
250 }
251}
252
253async function Create(index, model, options, callback) {
254 ScheduleResourceTick(global.resourceName)

Callers

nothing calls this directly

Calls 2

ParseErrorFunction · 0.85
ParseOperatorsFunction · 0.85

Tested by

no test coverage detected