Skip to content

Commit ca65858

Browse files
committed
Update README
1 parent 400b9af commit ca65858

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<li><strong><a href="https://github.com/Brayden/starbasedb/edit/main/README.md#deploy-a-starbasedb">Database Interface</a></strong> included out of the box deployed with your Cloudflare Worker</li>
2929
<li><strong><a href="https://starbasedb.hashnode.space/default-guide/import-export/sql-dump">Import & Export Data</a></strong> to import & extract your schema and data into a local `.sql`, `.json` or `.csv` file</li>
3030
<li><strong><a href="https://github.com/Brayden/starbasedb/pull/26">Bindable Microservices</a></strong> via templates to kickstart development and own the logic (e.g. user authentication)</li>
31+
<li><strong><a href="https://starbasedb.hashnode.space/default-guide/introduction/connect-external-database">Connect to External Databases</a></strong> such as Postgres and MySQL and access it with the methods above</li>
3132
<li><strong>Scale-to-zero Compute</strong> to reduce costs when your database is not in use</li>
3233
</ul>
3334
<br />

src/literest/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export class LiteREST {
5555
}
5656

5757
const schemaInfo = (await executeQuery(query, this.dataSource.source === Source.external ? {} : [], false, this.dataSource, this.env)) as any[];
58-
const pkColumns = schemaInfo
59-
// .filter(col => typeof col.pk === 'number' && col.pk > 0 && col.name !== null)
60-
.map(col => col.name as string);
58+
const pkColumns = schemaInfo.map(col => col.name as string);
6159
return pkColumns;
6260
}
6361

@@ -290,7 +288,7 @@ export class LiteREST {
290288
// Sanitize column names
291289
const columns = dataKeys.map(col => this.sanitizeIdentifier(col));
292290
const placeholders = columns.map(() => '?').join(', ');
293-
const query = `INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${placeholders})`;
291+
const query = `INSERT INTO ${schemaName ? `${schemaName}.` : ''}${tableName} (${columns.join(', ')}) VALUES (${placeholders})`;
294292

295293
// Map parameters using original data keys to get correct values
296294
const params = dataKeys.map(key => data[key]);
@@ -338,7 +336,7 @@ export class LiteREST {
338336
// Sanitize column names
339337
const columns = updateKeys.map(col => this.sanitizeIdentifier(col));
340338
const setClause = columns.map(col => `${col} = ?`).join(', ');
341-
const query = `UPDATE ${tableName} SET ${setClause} WHERE ${pkConditions.join(' AND ')}`;
339+
const query = `UPDATE ${schemaName ? `${schemaName}.` : ''}${tableName} SET ${setClause} WHERE ${pkConditions.join(' AND ')}`;
342340

343341
// Map parameters using original data keys to get correct values
344342
const params = updateKeys.map(key => data[key]);
@@ -379,7 +377,7 @@ export class LiteREST {
379377
// Sanitize column names
380378
const columns = dataKeys.map(col => this.sanitizeIdentifier(col));
381379
const setClause = columns.map(col => `${col} = ?`).join(', ');
382-
const query = `UPDATE ${tableName} SET ${setClause} WHERE ${pkConditions.join(' AND ')}`;
380+
const query = `UPDATE ${schemaName ? `${schemaName}.` : ''}${tableName} SET ${setClause} WHERE ${pkConditions.join(' AND ')}`;
383381

384382
// Map parameters using original data keys to get correct values
385383
const params = dataKeys.map(key => data[key]);
@@ -406,7 +404,7 @@ export class LiteREST {
406404
return createResponse(undefined, error, 400);
407405
}
408406

409-
const query = `DELETE FROM ${tableName} WHERE ${pkConditions.join(' AND ')}`;
407+
const query = `DELETE FROM ${schemaName ? `${schemaName}.` : ''}${tableName} WHERE ${pkConditions.join(' AND ')}`;
410408
const queries = [{ sql: query, params: pkParams }];
411409

412410
try {

0 commit comments

Comments
 (0)