Skip to content

Commit

Permalink
refactor: Make drivers classes instead of modules (#21)
Browse files Browse the repository at this point in the history
* WIP

* postgres

* Change driver from module to class
  • Loading branch information
kyleconroy authored Mar 3, 2024
1 parent ab29438 commit 029aec7
Show file tree
Hide file tree
Showing 5 changed files with 2,272 additions and 2,284 deletions.
18 changes: 9 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import {
} from "./gen/plugin/codegen_pb";

import { argName, colName } from "./drivers/utlis";
import betterSQLite3 from "./drivers/better-sqlite3";
import pg from "./drivers/pg";
import postgres from "./drivers/postgres";
import mysql2 from "./drivers/mysql2";
import { Driver as Sqlite3Driver } from "./drivers/better-sqlite3";
import { Driver as PgDriver } from "./drivers/pg";
import { Driver as PostgresDriver } from "./drivers/postgres";
import { Driver as MysqlDriver } from "./drivers/mysql2";

// Read input from stdin
const input = readInput();
Expand Down Expand Up @@ -81,16 +81,16 @@ interface Driver {
function createNodeGenerator(driver?: string): Driver {
switch (driver) {
case "mysql2": {
return mysql2;
return new MysqlDriver();
}
case "pg": {
return pg;
return new PgDriver();
}
case "postgres": {
return postgres;
return new PostgresDriver();
}
case "better-sqlite3": {
return betterSQLite3;
return new Sqlite3Driver();
}
}
throw new Error(`unknown driver: ${driver}`);
Expand Down Expand Up @@ -169,7 +169,7 @@ ${query.text}`
case ":execlastid": {
nodes.push(
driver.execlastidDecl(lowerName, textName, argIface, query.params)
)
);
break;
}
case ":one": {
Expand Down
Loading

0 comments on commit 029aec7

Please sign in to comment.