Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
OracleDB support #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Kononnable committed Apr 15, 2018
1 parent 4c6cfe5 commit d0fe49b
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 75 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ services:
# ports:
# - "1521:1521"
# environment:
# DB_SID: "ORCLCDB"
# SYS_PASSWORD: "Oradoc_db1"
# DB_SID: "sys"
# SYS_PASSWORD: "ORCLCDB"
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"handlebars": "^4.0.11",
"mssql": "^4.0.4",
"mysql": "^2.15.0",
"oracledb": "^2.0.15",
"oracledb": "^2.2.0",
"pg": "^7.4.0",
"reflect-metadata": "^0.1.10",
"typeorm": "0.2.0-alpha.44",
Expand Down
255 changes: 203 additions & 52 deletions src/drivers/OracleDriver.ts

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/entity.mst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Man
{{^relations}} @Column("{{sql_type}}",{ {{#is_generated}}
generated:true,{{/is_generated}}{{#is_nullable}}
nullable:true,{{/is_nullable}}{{^is_nullable}}
nullable:false,{{/is_nullable}}{{#lenght}}
nullable:false,{{/is_nullable}}{{#is_unique}}
unique: true,{{/is_unique}}{{#lenght}}
length:{{.}},{{/lenght}}{{#width}}
width:{{.}},{{/width}}{{#default}}
default:"{{.}}",{{/default}}{{#numericPrecision}}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var argv = Yargs.usage(
.option("e", {
alias: "engine",
describe: "Database engine.",
choices: ["mssql", "postgres", "mysql", "mariadb"],
choices: ["mssql", "postgres", "mysql", "mariadb", "oracle"],
default: "mssql"
})
.option("o", {
Expand Down
1 change: 1 addition & 0 deletions src/models/ColumnInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class ColumnInfo {
name: string = "";
default: string | null = null;
is_nullable: boolean = false;
is_unique: boolean = false;
ts_type:
| "number"
| "string"
Expand Down
1 change: 1 addition & 0 deletions test/drivers/MssqlDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('MssqlDriver', function () {
sql_type: 'int',
ts_type: 'number',
enumOptions: null,
is_unique:false,
relations: <RelationInfo[]>[]
})
let result = await driver.GetCoulmnsFromEntity(entities, 'schema');
Expand Down
4 changes: 4 additions & 0 deletions test/integration/entityTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("Platform specyfic types", async function () {
if (process.env.MYSQL_Skip == '0') dbDrivers.push('mysql')
if (process.env.MARIADB_Skip == '0') dbDrivers.push('mariadb')
if (process.env.MSSQL_Skip == '0') dbDrivers.push('mssql')
if (process.env.ORACLE_Skip == '0') dbDrivers.push('oracle')


let examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/entityTypes')
Expand Down Expand Up @@ -55,6 +56,9 @@ describe("Platform specyfic types", async function () {
case 'mariadb':
engine = await GTU.createMariaDBModels(filesOrgPathJS, resultsPath)
break;
case 'oracle':
engine = await GTU.createOracleDBModels(filesOrgPathJS, resultsPath)
break;

default:
console.log(`Unknown engine type`);
Expand Down
99 changes: 99 additions & 0 deletions test/integration/entityTypes/oracle/entity/Post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Entity, PrimaryColumn, Column } from "typeorm";

@Entity("Post")
export class Post {

@PrimaryColumn()
id: number;

@Column()
name: string;

@Column("char")
char: string;

@Column("nchar")
nchar: string;

@Column("nvarchar2")
nvarchar2: string;

@Column("varchar2")
varchar2: string;

@Column("long")
long: string;

@Column("raw")
raw: Buffer;

// @Column("long raw")
// long_raw: Buffer;

@Column("number")
number: number;

@Column("numeric")
numeric: number;

@Column("float")
float: number;

@Column("dec")
dec: number;

@Column("decimal")
decimal: number;

@Column("integer")
integer: number;

@Column("int")
int: number;

@Column("smallint")
smallint: number;

@Column("real")
real: number;

@Column("double precision")
double_precision: number;

@Column("date")
date: Date;

@Column("timestamp")
timestamp: Date;

@Column("timestamp with time zone")
timestamp_with_time_zone: Date;

@Column("timestamp with local time zone")
timestamp_with_local_time_zone: Date;

@Column("interval year to month")
interval_year_to_month: string;

@Column("interval day to second")
interval_day_to_second: string;

@Column("bfile")
bfile: Buffer;

@Column("blob")
blob: Buffer;

@Column("clob")
clob: string;

@Column("nclob")
nclob: string;

@Column("rowid")
rowid: number;

@Column("urowid")
urowid: number;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export class EverythingEntity {
@Column()
name: string;

@Column("text")
text: string;
// @Column("text")
// text: string;

@Column({ length: 32 })
shortTextColumn: string;
Expand Down
12 changes: 6 additions & 6 deletions test/integration/examples/sample2-one-to-one/entity/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Post {
onDelete: 'CASCADE'
})
@JoinColumn()
@Index({ unique: true })
// @Index({ unique: true })
category: PostCategory;

// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
Expand All @@ -33,7 +33,7 @@ export class Post {
cascade: true
})
@JoinColumn()
@Index({ unique: true })
// @Index({ unique: true })
details: PostDetails;

// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
Expand All @@ -42,7 +42,7 @@ export class Post {
cascade: true,
})
@JoinColumn()
@Index({ unique: true })
// @Index({ unique: true })
image: PostImage;

// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
Expand All @@ -51,7 +51,7 @@ export class Post {
onDelete: 'CASCADE'
})
@JoinColumn()
@Index({ unique: true })
// @Index({ unique: true })
metadata: PostMetadata | null;

// post has relation with details. full cascades here
Expand All @@ -60,13 +60,13 @@ export class Post {
onDelete: 'CASCADE'
})
@JoinColumn()
@Index({ unique: true })
// @Index({ unique: true })
information: PostInformation;

// post has relation with details. not cascades here. means cannot be persisted, updated or removed
@OneToOne(type => PostAuthor, author => author.post)
@JoinColumn()
@Index({ unique: true })
// @Index({ unique: true })
author: PostAuthor;

}
10 changes: 4 additions & 6 deletions test/utils/GeneralTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str
export async function createOracleDBModels(filesOrgPath: string, resultsPath: string): Promise<Engine> {
let driver: AbstractDriver;
driver = new OracleDriver();
await driver.ConnectToServer(String(process.env.ORACLE_Database), String(process.env.ORACLE_Host), Number(process.env.ORACLE_Port), String(process.env.ORACLE_Username), String(process.env.ORACLE_Password), yn(process.env.ORACLE_SSL));
await driver.ConnectToServer(String(process.env.ORACLE_Database), String(process.env.ORACLE_Host), Number(process.env.ORACLE_Port), String(process.env.ORACLE_UsernameSys), String(process.env.ORACLE_PasswordSys), yn(process.env.ORACLE_SSL));

if (! await driver.CheckIfDBExists(String(process.env.ORACLE_Database)))
await driver.CreateDB(String(process.env.ORACLE_Database));
if (await driver.CheckIfDBExists(String(process.env.ORACLE_Username)))
await driver.DropDB(String(process.env.ORACLE_Username));
await driver.CreateDB(String(process.env.ORACLE_Username));
await driver.DisconnectFromServer();

let connOpt: ConnectionOptions = {
Expand Down Expand Up @@ -281,11 +282,8 @@ export async function createOracleDBModels(filesOrgPath: string, resultsPath: st
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',

});



return engine;
}

Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"strictNullChecks": true,
"moduleResolution": "node",
"outDir": "dist",
"newLine": "LF"
"newLine": "LF",
"lib": [
"es2017"
]
},
"include": [
"src",
Expand Down

0 comments on commit d0fe49b

Please sign in to comment.