82 lines
1.4 KiB
JavaScript
82 lines
1.4 KiB
JavaScript
/*
|
|
|
|
Copyright (c) 2020, 2023, The Unified Company.
|
|
|
|
This code is part of Unify.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
|
|
as published by the ESA.
|
|
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
|
|
|
|
https://unifyjs.org
|
|
|
|
*/
|
|
|
|
import querySQL from '../../unify/querySQL.js';
|
|
|
|
import joinSQL from '../../unify/joinSQL.js';
|
|
|
|
import tools from '../../unify/tools.js';
|
|
|
|
|
|
export default class queryCount{
|
|
|
|
createJoin() {
|
|
|
|
var join = new joinSQL();
|
|
|
|
join.table = this.tableName;
|
|
|
|
join.name = "children";
|
|
|
|
join.left.table = join.name;
|
|
|
|
join.right.column = this.getRight() + "_id";
|
|
|
|
join.find( "signed", "true" );
|
|
//join.find( this.tableName + ".joined", "true" ); // please fix
|
|
|
|
return join;
|
|
|
|
}
|
|
|
|
createQuery() {
|
|
|
|
var object = this.getObject();
|
|
|
|
|
|
var leftTable = this.parentName;
|
|
|
|
var rightTable = object.propertyName;
|
|
|
|
var id = this.collection.getID();
|
|
|
|
var joinTableName = leftTable + "_" + rightTable;
|
|
|
|
|
|
var query = new querySQL();
|
|
|
|
query.table = joinTableName;
|
|
|
|
query.find( this.getLeft() + "_id", id );
|
|
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
query() {
|
|
|
|
var query = this.createQuery();
|
|
|
|
var join = this.createJoin();
|
|
|
|
query.addJoin( join );
|
|
|
|
// bug : todo : count not length
|
|
return global.database.query( query ).length;
|
|
|
|
}
|
|
|
|
} |