nexusql 0.8.1 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/cli.js +49 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +42 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -258,4 +258,9 @@ interface InitOptions {
|
|
|
258
258
|
*/
|
|
259
259
|
declare function init(options?: InitOptions): Promise<void>;
|
|
260
260
|
|
|
261
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Test database connection.
|
|
263
|
+
*/
|
|
264
|
+
declare function testConnection(): Promise<void>;
|
|
265
|
+
|
|
266
|
+
export { Database, type DbUrlParts, MigrationRunner, type NexusqlConfig, buildDbUrl, createMigrationFile, dbmlToSql, filterSchemaMigrations, gen, generateConfigTemplate, getDatabaseUrl, getMostRecentMigration, init, listMigrations, loadConfig, markApplied, migrate, parseAndEncodeDbUrl, parseMigrationFile, runMigra, status, testConnection, up, updateMigrationFile };
|
package/dist/index.js
CHANGED
|
@@ -1855,7 +1855,13 @@ var Database = class _Database {
|
|
|
1855
1855
|
for (const ext of extensions) {
|
|
1856
1856
|
try {
|
|
1857
1857
|
await this.exec(`CREATE EXTENSION IF NOT EXISTS "${ext}";`);
|
|
1858
|
-
} catch {
|
|
1858
|
+
} catch (error) {
|
|
1859
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1860
|
+
throw new Error(
|
|
1861
|
+
`Failed to install extension "${ext}": ${message}
|
|
1862
|
+
Make sure the extension is installed on your PostgreSQL server.
|
|
1863
|
+
For pgvector: https://github.com/pgvector/pgvector#installation`
|
|
1864
|
+
);
|
|
1859
1865
|
}
|
|
1860
1866
|
}
|
|
1861
1867
|
}
|
|
@@ -3992,6 +3998,40 @@ async function init(options = {}) {
|
|
|
3992
3998
|
console.log(' 3. Run "nexusql gen" to generate migration SQL');
|
|
3993
3999
|
console.log(' 4. Run "nexusql migrate" to create and apply migrations\n');
|
|
3994
4000
|
}
|
|
4001
|
+
|
|
4002
|
+
// src/commands/test-connection.ts
|
|
4003
|
+
async function testConnection() {
|
|
4004
|
+
console.log(source_default.bold("Testing database connection...\n"));
|
|
4005
|
+
try {
|
|
4006
|
+
const config = await loadConfig();
|
|
4007
|
+
const rawUrl = getDatabaseUrl(config);
|
|
4008
|
+
const parsed = parseAndEncodeDbUrl(rawUrl);
|
|
4009
|
+
console.log(source_default.cyan("Connection details:"));
|
|
4010
|
+
console.log(source_default.dim(" Protocol:"), parsed.protocol);
|
|
4011
|
+
console.log(source_default.dim(" User:"), parsed.user);
|
|
4012
|
+
console.log(source_default.dim(" Host:"), parsed.host);
|
|
4013
|
+
console.log(source_default.dim(" Port:"), parsed.port);
|
|
4014
|
+
console.log(source_default.dim(" Database:"), parsed.database);
|
|
4015
|
+
console.log(source_default.dim(" Password:"), "***" + decodeURIComponent(parsed.password).slice(-4));
|
|
4016
|
+
console.log();
|
|
4017
|
+
const db = new Database(rawUrl);
|
|
4018
|
+
const result = await db.query("SELECT current_user, current_database(), version()");
|
|
4019
|
+
console.log(source_default.green("\u2713 Connection successful!\n"));
|
|
4020
|
+
console.log(source_default.cyan("Server info:"));
|
|
4021
|
+
console.log(source_default.dim(" Current user:"), result.rows[0].current_user);
|
|
4022
|
+
console.log(source_default.dim(" Current database:"), result.rows[0].current_database);
|
|
4023
|
+
console.log(source_default.dim(" PostgreSQL version:"), result.rows[0].version.split(",")[0]);
|
|
4024
|
+
} catch (error) {
|
|
4025
|
+
console.log(source_default.red("\u2717 Connection failed!\n"));
|
|
4026
|
+
console.error(source_default.red("Error:"), error.message);
|
|
4027
|
+
console.log(source_default.yellow("\nTroubleshooting tips:"));
|
|
4028
|
+
console.log(" \u2022 Check DATABASE_URL in your .env file");
|
|
4029
|
+
console.log(" \u2022 Ensure special characters in password are NOT URL-encoded");
|
|
4030
|
+
console.log(" \u2022 Verify the database server is running");
|
|
4031
|
+
console.log(" \u2022 Check host, port, username, and database name");
|
|
4032
|
+
process.exit(1);
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
3995
4035
|
export {
|
|
3996
4036
|
Database,
|
|
3997
4037
|
MigrationRunner,
|
|
@@ -4012,6 +4052,7 @@ export {
|
|
|
4012
4052
|
parseMigrationFile,
|
|
4013
4053
|
runMigra,
|
|
4014
4054
|
status,
|
|
4055
|
+
testConnection,
|
|
4015
4056
|
up,
|
|
4016
4057
|
updateMigrationFile
|
|
4017
4058
|
};
|