Replace raw SQL in StartPlan with query builder code
Running this code results in the following error: TypeError: subQueryBuilder.getParameters is not a function (it is undefined) at createFromAlias (http://localhost:8081/index.bundle//&platform=android&dev=t y=false&app=com.massive&modulesOnly=false&runModule=true:205802:59) at from (http://localhost:8081/index.bundle//&platform=android&dev=true&minify= =com.massive&modulesOnly=false&runModule=true:201576:45) at ?anon_0_ (http://localhost:8081/index.bundle//&platform=android&dev=true&min &app=com.massive&modulesOnly=false&runModule=true:316375:209) at next (native) at asyncGeneratorStep (http://localhost:8081/index.bundle//&platform=android&de nify=false&app=com.massive&modulesOnly=false&runModule=true:28380:26) at _next (http://localhost:8081/index.bundle//&platform=android&dev=true&minify p=com.massive&modulesOnly=false&runModule=true:28399:29) at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&mi e&app=com.massive&modulesOnly=false&runModule=true:28404:14) at tryCallTwo (/root/react-native/packages/react-native/ReactAndroid/hermes-eng Release/4i495j47/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:61:9) at doResolve (/root/react-native/packages/react-native/ReactAndroid/hermes-engi elease/4i495j47/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:216:25) at Promise (/root/react-native/packages/react-native/ReactAndroid/hermes-engine ease/4i495j47/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:82:14) at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&mi e&app=com.massive&modulesOnly=false&runModule=true:28396:25) at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&mi e&app=com.massive&modulesOnly=false&runModule=true:316420:14) at callback (http://localhost:8081/index.bundle//&platform=android&dev=true&min &app=com.massive&modulesOnly=false&runModule=true:145400:29) at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&mi e&app=com.massive&modulesOnly=false&runModule=true:145419:27) at commitHookEffectListMount (http://localhost:8081/index.bundle//&platform=and true&minify=false&app=com.massive&modulesOnly=false&runModule=true:94929:38) at commitPassiveMountOnFiber (http://localhost:8081/index.bundle//&platform=and true&minify=false&app=com.massive&modulesOnly=false&runModule=true:96130:44) at commitPassiveMountEffects_complete (http://localhost:8081/index.bundle//&pla roid&dev=true&minify=false&app=com.massive&modulesOnly=false&runModule=true:96102:4 at commitPassiveMountEffects_begin (http://localhost:8081/index.bundle//&platfo d&dev=true&minify=false&app=com.massive&modulesOnly=false&runModule=true:96092:47) at commitPassiveMountEffects (http://localhost:8081/index.bundle//&platform=and true&minify=false&app=com.massive&modulesOnly=false&runModule=true:96082:40) at flushPassiveEffectsImpl (http://localhost:8081/index.bundle//&platform=andro ue&minify=false&app=com.massive&modulesOnly=false&runModule=true:97758:34) at flushPassiveEffects (http://localhost:8081/index.bundle//&platform=android&d inify=false&app=com.massive&modulesOnly=false&runModule=true:97713:43) at performSyncWorkOnRoot (http://localhost:8081/index.bundle//&platform=android &minify=false&app=com.massive&modulesOnly=false&runModule=true:97003:28) at flushSyncCallbacks (http://localhost:8081/index.bundle//&platform=android&de nify=false&app=com.massive&modulesOnly=false&runModule=true:86202:36) at flushSyncCallbacksOnlyInLegacyMode (http://localhost:8081/index.bundle//&pla
This commit is contained in:
parent
8648cf166e
commit
ebe9a392ca
|
@ -45,18 +45,30 @@ export default function StartPlan() {
|
|||
const questions = workouts
|
||||
.map((workout, index) => `('${workout}',${index})`)
|
||||
.join(",");
|
||||
const select = `
|
||||
SELECT workouts.name, COUNT(sets.id) as total, sets.sets
|
||||
FROM (select 0 as name, 0 as sequence union values ${questions}) as workouts
|
||||
LEFT JOIN sets ON sets.name = workouts.name
|
||||
AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime')
|
||||
AND NOT sets.hidden
|
||||
GROUP BY workouts.name
|
||||
ORDER BY workouts.sequence
|
||||
LIMIT -1
|
||||
OFFSET 1
|
||||
`;
|
||||
const newCounts = await AppDataSource.manager.query(select);
|
||||
const newCounts = await AppDataSource.manager
|
||||
.createQueryBuilder()
|
||||
.select("workouts.name")
|
||||
.addSelect("COUNT(sets.id)", "total")
|
||||
.addSelect("sets.sets")
|
||||
.from((qb) => {
|
||||
const subQuery = qb
|
||||
.subQuery()
|
||||
.select("0", "name")
|
||||
.addSelect("0", "sequence")
|
||||
.from("workouts", "workouts")
|
||||
.getQuery();
|
||||
return `(${subQuery} UNION ALL values ${questions})`;
|
||||
}, "workouts")
|
||||
.leftJoin(
|
||||
"sets",
|
||||
"sets",
|
||||
"sets.name = workouts.name AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime') AND NOT sets.hidden"
|
||||
)
|
||||
.groupBy("workouts.name")
|
||||
.orderBy("workouts.sequence")
|
||||
.limit(-1)
|
||||
.offset(1)
|
||||
.getRawMany();
|
||||
console.log(`${StartPlan.name}.focus:`, { newCounts });
|
||||
setCounts(newCounts);
|
||||
}, [workouts]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user