Skip to content

Implemented MySQLAdapter with tests and added SchemaField interface#11

Merged
Sauvikn98 merged 10 commits into
Solvaratech:devfrom
AryanMishra1789:feature/mysql-adapter
Mar 24, 2026
Merged

Implemented MySQLAdapter with tests and added SchemaField interface#11
Sauvikn98 merged 10 commits into
Solvaratech:devfrom
AryanMishra1789:feature/mysql-adapter

Conversation

@AryanMishra1789
Copy link
Copy Markdown
Contributor

Description

  • Implemented MySQLAdapter extending BaseAdapter with methods: connect, disconnect, getCollections, insertDocuments, ensureCollection.
  • Added unit tests in MySQLAdapter.test.ts using vitest with mocked mysql2/promise.
  • Introduced SchemaField interface in types.ts for table schema support.

Testing

  • All unit tests passed successfully, verifying the functionality of the MySQLAdapter.

#3

@Sauvikn98 Sauvikn98 requested review from Sauvikn98 and dhanmoni and removed request for dhanmoni March 23, 2026 06:19
Comment thread src/generator/adapters/MySQLAdapter.ts Outdated
if (!this.connection) throw new Error('Not connected');
const placeholders = documents.map(() => '(?)').join(', ');
const values = documents.map((doc) => Object.values(doc));
const query = `INSERT INTO ${collection} VALUES ${placeholders}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical SQL Injection Vulnerability

@Sauvikn98
Copy link
Copy Markdown
Contributor

Thanks @AryanMishra1789 for this contribution! The adapter structure is solid and your testing approach with vitest mocking is great. Before we can merge, please address these important issues:

Critical: SQL Injection Vulnerabilities

Multiple methods directly interpolate table/field names without escaping:

  • insertDocuments (line 30): INSERT INTO ${collection}
  • ensureCollection (line 41): CREATE TABLE IF NOT EXISTS ${collectionName}
  • clearCollection (line 47): DELETE FROM ${collection}
  • collectionExists (line 53): Table name and WHERE clause
  • getCollectionDetails (line 61): DESCRIBE ${collection}
  • getDocumentCount (line 67): SELECT FROM ${collection}
  • validateReference (line 74): ${collectionName} and ${fieldName}

Fix: Add an identifier escaping helper:

private escapeIdentifier(id: string): string {
  return '`' + id.replace(/`/g, '``') + '`';
}

High: insertDocuments Logic

The current implementation may not handle column ordering correctly:

const placeholders = documents.map(() => '(?)').join(', ');
const values = documents.map((doc) => Object.values(doc));

This doesn't explicitly list columns. Compare with other adapters to align on the correct pattern.

Medium Issues

  1. Schema creation is incomplete - Handle PRIMARY KEY, NOT NULL, DEFAULT, and other constraints
  2. addForeignKeyConstraints() throws NotImplementedError - Should be implemented or properly inherited
  3. Type safety - getCollectionDetails() returns any instead of proper CollectionDetails type
  4. Missing implementation - getCollectionSchema() method

Test Coverage

Consider adding tests for:

  • Connection failures
  • Invalid table/field names
  • Edge cases in data insertion

@AryanMishra1789
Copy link
Copy Markdown
Contributor Author

The PR feedback has been addressed. I have also added SQLiteAdapter.ts and SQLiteAdapter.test.ts to fully implement and test secure SQLite generation.

@Sauvikn98 Sauvikn98 changed the base branch from main to dev March 24, 2026 05:22
@Sauvikn98
Copy link
Copy Markdown
Contributor

Sauvikn98 commented Mar 24, 2026

@AryanMishra1789 looks good to me. Merging it. Thank you for the contribution.

@Sauvikn98 Sauvikn98 merged commit 8c23428 into Solvaratech:dev Mar 24, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants