mirror of
https://github.com/HeyPuter/puter
synced 2024-11-15 06:15:47 +00:00
fix: do not delegate to select on read like ever that is really dumb
This commit is contained in:
parent
9b39309e18
commit
a2a10b94be
@ -67,15 +67,13 @@ const _fetch_based_on_complex_id = async (self, id) => {
|
|||||||
let predicate = new And({ children: key_eqs });
|
let predicate = new And({ children: key_eqs });
|
||||||
|
|
||||||
// Perform a select
|
// Perform a select
|
||||||
const entities = await svc_es.select({ predicate });
|
const entity = await svc_es.read({ predicate });
|
||||||
if ( entities.length === 0 ) {
|
if ( ! entity ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('WHAT ISAGERSGAREWHGwr', entities)
|
|
||||||
|
|
||||||
// Ensure there is only one result
|
// Ensure there is only one result
|
||||||
return entities[0];
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _fetch_based_on_either_id = async (self, uid, id) => {
|
const _fetch_based_on_either_id = async (self, uid, id) => {
|
||||||
|
@ -44,22 +44,41 @@ class SQLES extends BaseES {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async read (uid) {
|
async read (uid) {
|
||||||
const id_prop = this.om.properties[this.om.primary_identifier];
|
|
||||||
let id_col =
|
|
||||||
id_prop.descriptor.sql?.column_name ?? id_prop.name;
|
|
||||||
|
|
||||||
console.log('CALLING READ WITH UID ', uid);
|
const [stmt_where, where_vals] = await (async () => {
|
||||||
// Temporary hack until multiple identifiers are supported
|
if ( typeof uid !== 'object' ) {
|
||||||
// (allows us to query using an internal ID; users can't do this)
|
const id_prop =
|
||||||
if ( typeof uid === 'number' ) {
|
this.om.properties[this.om.primary_identifier];
|
||||||
id_col = 'id';
|
let id_col =
|
||||||
}
|
id_prop.descriptor.sql?.column_name ?? id_prop.name;
|
||||||
|
// Temporary hack until multiple identifiers are supported
|
||||||
|
// (allows us to query using an internal ID; users can't do this)
|
||||||
|
if ( typeof uid === 'number' ) {
|
||||||
|
id_col = 'id';
|
||||||
|
}
|
||||||
|
return [` WHERE ${id_col} = ?`, [uid]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! uid.hasOwnProperty('predicate') ) {
|
||||||
|
throw new Error(
|
||||||
|
'SQLES.read does not understand this input: ' +
|
||||||
|
'object with no predicate property',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let predicate = uid.predicate; // uid is actually a predicate
|
||||||
|
if ( predicate instanceof Predicate ) {
|
||||||
|
predicate = await this.om_to_sql_condition_(predicate);
|
||||||
|
}
|
||||||
|
const stmt_where = ` WHERE ${predicate.sql} LIMIT 1` ;
|
||||||
|
const where_vals = predicate.values;
|
||||||
|
return [stmt_where, where_vals];
|
||||||
|
})();
|
||||||
|
|
||||||
const stmt =
|
const stmt =
|
||||||
`SELECT * FROM ${this.om.sql.table_name} WHERE ${id_col} = ?`;
|
`SELECT * FROM ${this.om.sql.table_name}${stmt_where}`;
|
||||||
|
|
||||||
const rows = await this.db.read(
|
const rows = await this.db.read(
|
||||||
stmt, [uid]
|
stmt, where_vals
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( rows.length === 0 ) {
|
if ( rows.length === 0 ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user