Skip to content

Conversation

@HungKNguyen
Copy link

Continuation of #748

Changed the base branch to allow edits by maintainers

@nguyenalter
Copy link
Contributor

Hi @HungKNguyen, could you check if your master branch is protected by any means? You may check it via https://github.com/hungknguyen/dbml/settings/branches.

If your master is protected, I cannot push commit to your forked repository

@HungKNguyen
Copy link
Author

Hi @HungKNguyen, could you check if your master branch is protected by any means? You may check it via https://github.com/hungknguyen/dbml/settings/branches.

If your master is protected, I cannot push commit to your forked repository

@nguyenalter I'm not seeing any protection on the branch, are you having trouble pushing? Maybe you can double check the origin?

@nguyenalter
Copy link
Contributor

Hi @HungKNguyen, could you check if your master branch is protected by any means? You may check it via https://github.com/hungknguyen/dbml/settings/branches.
If your master is protected, I cannot push commit to your forked repository

@nguyenalter I'm not seeing any protection on the branch, are you having trouble pushing? Maybe you can double check the origin?

When I try to push my commit to your forked repository, It shows 403 error:

git push HungKNguyen HEAD:master
remote: Permission to hungknguyen/dbml.git denied to nguyenalter.
fatal: unable to access 'https://github.com/hungknguyen/dbml/': The requested URL returned error: 403

I think you can either:

  • Add me as a collaborators in your forked repo
  • Try to checkout another branch (not master) in your forked repo and re-open another PR

@HungKNguyen please look into this, thank you for your time.

@HungKNguyen
Copy link
Author

I think you can either:

  • Add me as a collaborators in your forked repo
  • Try to checkout another branch (not master) in your forked repo and re-open another PR

@HungKNguyen please look into this, thank you for your time.

@nguyenalter I just added you as a collaborator, thank you for your time as well

Copy link
Contributor

@nguyenalter nguyenalter left a comment

Choose a reason for hiding this comment

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

Please also update the description in packages/dbml-cli/src/cli/index.js (see TODO) to introduce your new sqlite and oracle options

@@ -0,0 +1,481 @@
import * as oracledb from 'oracledb';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please help add a comment to reference https://node-oracledb.readthedocs.io/en/latest/user_guide/installation.html#quickstart so we can check the doc more easily

Comment on lines +19 to +35
// Parse connection string to extract connection details
// Expected format: user/password@hostname/servicename
const regex = /^(.*?)\/(.*)@(.*)$/;
const match = connection.match(regex);

if (!match) {
throw new Error('Invalid Oracle connection string format. Expected: user/password@hostname/servicename');
}

const [, user, password, connectionString] = match;

// Set connection options
const connectionConfig: oracledb.ConnectionAttributes = {
user,
password,
connectString: connectionString,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move the parse connection string to a dedicated method, e.g:

parseConnectionString = (connection) => config

@@ -0,0 +1,389 @@
import type { Database } from 'better-sqlite3';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please help add https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#api to the start of this file for future reference

Comment on lines +25 to +26
try {
return new DatabaseConstructor(connection, { readonly: true, fileMustExist: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure the db is connected successfully, please try to run a simple query like this:

Suggested change
try {
return new DatabaseConstructor(connection, { readonly: true, fileMustExist: true });
try {
const db = new DatabaseConstructor(connection, { readonly: true, fileMustExist: true });
db.exec('SELECT 1');
return db;

DATA_PRECISION,
DATA_SCALE,
NULLABLE,
DATA_DEFAULT,
Copy link
Contributor

Choose a reason for hiding this comment

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

https://docs.oracle.com/en/database/oracle/oracle-database/23/refrn/ALL_TAB_COLUMNS.html

Oracle DB v23 introduces DATA_DEFAULT_VC to get default value for the column. Could you improve the logic to retrieve the default value since using DATA_DEFAULT will always return the LONG type which will infer as number. This will cause expression like current_timestamp to be treated as number when converting to DBML which is incorrect.

My suggestion is to use DATA_DEFAULT_VC for Oracle DB >= 23 and fallback to DATA_DEFAULT for older versions.

return {
name: COLUMN_NAME,
type: actualType,
dbdefault: getDbDefault(DATA_DEFAULT, defaultValueType),
Copy link
Contributor

Choose a reason for hiding this comment

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

You must ignore column with IDENTITY_COLUMN === 'YES' because it is mapped to increment option, we don't want to use the default auto-generated value from Oracle here.

Suggested change
dbdefault: getDbDefault(DATA_DEFAULT, defaultValueType),
dbdefault: `IDENTITY_COLUMN === 'YES' ? null : getDbDefault(DATA_DEFAULT, defaultValueType),

Comment on lines +189 to +199
SELECT
I.TABLE_NAME,
I.INDEX_NAME,
I.INDEX_TYPE,
I.UNIQUENESS,
IC.COLUMN_NAME,
IC.COLUMN_POSITION
FROM ALL_INDEXES I
JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME AND I.OWNER = IC.INDEX_OWNER
WHERE I.OWNER = :schemaName
ORDER BY I.TABLE_NAME, I.INDEX_NAME, IC.COLUMN_POSITION
Copy link
Contributor

Choose a reason for hiding this comment

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

Oracle will auto add index for primary key so you will need to exclude those auto-generated indexes from the DBML.

Suggested change
SELECT
I.TABLE_NAME,
I.INDEX_NAME,
I.INDEX_TYPE,
I.UNIQUENESS,
IC.COLUMN_NAME,
IC.COLUMN_POSITION
FROM ALL_INDEXES I
JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME AND I.OWNER = IC.INDEX_OWNER
WHERE I.OWNER = :schemaName
ORDER BY I.TABLE_NAME, I.INDEX_NAME, IC.COLUMN_POSITION
SELECT
I.TABLE_NAME,
I.INDEX_NAME,
I.INDEX_TYPE,
I.UNIQUENESS,
IC.COLUMN_NAME,
IC.COLUMN_POSITION
FROM ALL_INDEXES I
JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME AND I.OWNER = IC.INDEX_OWNER
JOIN ALL_CONSTRAINTS C ON I.INDEX_NAME = C.INDEX_NAME AND I.OWNER = C.OWNER AND C.CONSTRAINT_TYPE != 'P'
WHERE I.OWNER = :schemaName
ORDER BY I.TABLE_NAME, I.INDEX_NAME, IC.COLUMN_POSITION

@H-DNA H-DNA changed the title feat(dbml/connector): add sqlite and oracle connectors cont. Support sqlite and oracle connectors Nov 4, 2025
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