{"id":13388846,"url":"https://github.com/loopbackio/loopback-connector-oracle","last_synced_at":"2025-12-15T18:31:20.339Z","repository":{"id":42657454,"uuid":"9348685","full_name":"loopbackio/loopback-connector-oracle","owner":"loopbackio","description":"Connect Loopback to Oracle","archived":false,"fork":false,"pushed_at":"2023-12-15T17:35:28.000Z","size":518,"stargazers_count":28,"open_issues_count":3,"forks_count":31,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-09-27T04:02:36.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://loopback.io/doc/en/lb3/Oracle-connector.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loopbackio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-04-10T15:00:59.000Z","updated_at":"2022-03-24T12:38:09.000Z","dependencies_parsed_at":"2023-12-15T18:48:38.294Z","dependency_job_id":null,"html_url":"https://github.com/loopbackio/loopback-connector-oracle","commit_stats":{"total_commits":320,"total_committers":41,"mean_commits":7.804878048780488,"dds":"0.43437499999999996","last_synced_commit":"ba7f88886dd49b091c54e25d5d08421ac934c680"},"previous_names":["strongloop/loopback-connector-oracle"],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/loopbackio/loopback-connector-oracle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-oracle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-oracle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-oracle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-oracle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopbackio","download_url":"https://codeload.github.com/loopbackio/loopback-connector-oracle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-oracle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278050237,"owners_count":25921569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-02T02:00:08.890Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T13:00:55.269Z","updated_at":"2025-10-11T11:02:12.802Z","avatar_url":"https://github.com/loopbackio.png","language":"JavaScript","readme":"# loopback-connector-oracle\n\n[Oracle](https://www.oracle.com/database/index.html) is an object-relational database management system produced by Oracle Corporation. The `loopback-connector-oracle` module is the Oracle connector for the LoopBack framework based on the [node-oracledb](https://github.com/oracle/node-oracledb) module.\n\n## Prerequisites\n\n**Node.js**: The Oracle connector requires Node.js version 6.x and up.\n\n**Windows**: On 32-bit Windows systems, you must use the 32-bit version of Node.js. On 64-bit Windows systems, you must use the 64-bit version of Node.js. For more information, see [Node-oracledb Installation on Windows](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md#-7-node-oracledb-installation-on-windows).\n\n**Oracle**: The Oracle connector requires Oracle client libraries 11.2+ and can connect to Oracle Database Server 9.2+.\n\n## Installation\n\nBefore installing this module, please follow instructions at [https://oracle.github.io/node-oracledb/INSTALL.html](https://oracle.github.io/node-oracledb/INSTALL)\nto make sure all the prerequisites are satisfied.\n\nIn your application root directory, enter this command to install the connector:\n\n```shell\n$ npm install loopback-connector-oracle --save\n```\n\nIf you create a Oracle data source using the data source generator as described below, you don’t have to do this, since the generator will run `npm install` for you.\n\nThe `libaio` library is required on Linux systems:\n\nOn Ubuntu/Debian, get it with this command:\n\n```\nsudo apt-get install libaio1\n```\n\nOn Fedora/CentOS/RHEL, get it with this command:\n\n```\nsudo yum install libaio\n```\n\n## Creating an Oracle data source\n\nFor LoopBack 4 users, use the LoopBack 4\n[Command-line interface](https://loopback.io/doc/en/lb4/Command-line-interface.html)\nto generate a DataSource with Oracle connector to your LB4 application. Run\n[`lb4 datasource`](https://loopback.io/doc/en/lb4/DataSource-generator.html), it\nwill prompt for configurations such as host, post, etc. that are required to\nconnect to an Oracle database.\n\nAfter setting it up, the configuration can be found under\n`src/datasources/\u003cDataSourceName\u003e.datasource.ts`, which would look like this:\n\n```ts\nconst config = {\n  name: \"db\",\n  connector: \"oracle\",\n  tns: \"\",\n  host: \"localhost\",\n  port: 1521,\n  user: \"admin\",\n  password: \"pass\",\n  database: \"XE\",\n};\n```\n\n\u003cdetails\u003e\u003csummary markdown=\"span\"\u003e\u003cstrong\u003eFor LoopBack 3 users\u003c/strong\u003e\u003c/summary\u003e\n\nUse the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a Oracle data source to your application.\nThe generator will prompt for the database server hostname, port, and other settings\nrequired to connect to a Oracle database. It will also run the `npm install` command above for you.\n\nThe entry in the application's `/server/datasources.json` will look like this:\n\n{% include code-caption.html content=\"/server/datasources.json\" %}\n\n```javascript\n\"mydb\": {\n  \"name\": \"mydb\",\n  \"connector\": \"oracle\",\n  \"tns\": \"demo\",\n  \"host\": \"myserver\",\n  \"port\": 1521,\n  \"database\": \"mydb\",\n  \"password\": \"mypassword\",\n  \"user\": \"admin\"\n }\n```\n\n\u003c/details\u003e\n\nEdit `\u003cDataSourceName\u003e.datasources.ts` to add any other additional properties\nthat you require.\n\n## Connector properties\n\nThe connector properties depend on [naming methods](http://docs.oracle.com/cd/E11882_01/network.112/e10836/naming.htm#NETAG008) you use for the Oracle database.\nLoopBack supports three naming methods:\n\n- Easy connect: host/port/database.\n- Local naming (TNS): alias to a full connection string that can specify all the attributes that Oracle supports.\n- Directory naming (LDAP): directory for looking up the full connection string that can specify all the attributes that Oracle supports.\n\n### Easy Connect\n\nEasy Connect is the simplest form that provides out-of-the-box TCP/IP connectivity to databases.\nThe data source then has the following settings.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth width=\"200\"\u003eProperty\u003c/th\u003e\n      \u003cth width=\"200\"\u003eType\u003c/th\u003e\n      \u003cth width=\"150\"\u003eDefault\u003c/th\u003e\n      \u003cth width=\"350\"\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ehost or hostname\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003elocalhost\u003c/td\u003e\n      \u003ctd\u003eHost name or IP address of the Oracle database server\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eport\u003c/td\u003e\n      \u003ctd\u003eNumber\u003c/td\u003e\n      \u003ctd\u003e1521\u003c/td\u003e\n      \u003ctd\u003ePort number of the Oracle database server\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eusername or user\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e\u0026nbsp;\u003c/td\u003e\n      \u003ctd\u003eUser name to connect to the Oracle database server\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003epassword\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e\u0026nbsp;\u003c/td\u003e\n      \u003ctd\u003ePassword to connect to the Oracle database server\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003edatabase\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003eXE\u003c/td\u003e\n      \u003ctd\u003eOracle database listener name\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nFor example (LB4 form):\n\n{% include code-caption.html content=\"src/datasources/db.datasource.ts\" %}\n\n```ts\nconst config = {\n  name: \"db\",\n  connector: \"oracle\",\n  host: \"oracle-demo.strongloop.com\",\n  port: 1521,\n  user: \"admin\",\n  password: \"pass\",\n  database: \"XE\",\n};\n```\n\n### Local and directory naming\n\nBoth local and directory naming require that you place configuration files in a TNS admin directory, such as `/oracle/admin`.\n\n**sqlnet.ora**\n\nThis specifies the supported naming methods; for example:\n\n```\nNAMES.DIRECTORY_PATH=(LDAP,TNSNAMES,EZCONNECT)\n```\n\n**nsnames.ora**\n\nThis maps aliases to connection stringsl for example:\n\n```\ndemo1=(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=demo.strongloop.com)(PORT=1521)))\n```\n\n**ldap.ora**\n\nThis configures the LDAP server.\n\n```\nDIRECTORY_SERVERS=(localhost:1389)\nDEFAULT_ADMIN_CONTEXT=\"dc=strongloop,dc=com\"\nDIRECTORY_SERVER_TYPE=OID\n```\n\n#### Set up TNS_ADMIN environment variable\n\nFor the Oracle connector to pick up the configurations, you must set the environment variable 'TNS_ADMIN' to the directory containing the `.ora` files.\n\n```\nexport TNS_ADMIN=\u003cdirectory containing .ora files\u003e\n```\n\nNow you can use either the TNS alias or LDAP service name to configure a data source:\n\n```ts\nconst config = {\n  name: \"db\",\n  connector: \"oracle\",\n  tns: \"demo\", // The tns property can be a tns name or LDAP service name\n  username: \"demo\",\n  password: \"L00pBack\",\n});\n```\n\n### Connection pooling options\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eProperty name\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n      \u003cth\u003eDefault value\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eminConn\u003c/td\u003e\n      \u003ctd\u003eMinimum number of connections in the connection pool\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003emaxConn\u003c/td\u003e\n      \u003ctd\u003eMaximum number of connections in the connection pool\u003c/td\u003e\n      \u003ctd\u003e10\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eincrConn\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003eIncremental number of connections for the connection pool.\u003c/p\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etimeout\u003c/td\u003e\n      \u003ctd\u003e\n        Time-out period in seconds for a connection in the connection pool.\n          The Oracle connector\n          will terminate connections in this\n          connection pool that are idle longer than the time-out period.\n      \u003c/td\u003e\n      \u003ctd\u003e10\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nFor example,\n\n{% include code-caption.html content=\"src/datasources/db.datasource.ts\" %}\n\n```ts\nconst config = {\n  name: \"db\",\n  connector: \"oracle\",\n  minConn:1,\n  maxConn:5,\n  incrConn:1,\n  timeout: 10,\n  ...\n};\n```\n\n### Connection troubleshooting\n\nIf you encounter this error:\n\n```\nError: ORA-24408: could not generate unique server group name\n```\n\nThen the Oracle 11g client requires an entry with your hostname pointing to\n`127.0.0.1`.\n\nTo resolve:\n\nGet your hostname. Check your hostname by running this command (for example, if your machine's name is \"earth\"):\n\n```\n$ hostname\nearth\n```\n\nUpdate `/etc/hosts` and map `127.0.0.1` to your hostname \"earth\":\n\n```\n...\n127.0.0.1 localhost earth\n...\n```\n\nVerify the fix. Run the app:\n\n```\n$ npm start\n```\n\nFor more information, see [StackOverflow question](http://stackoverflow.com/questions/10484231/ora-24408-could-not-generate-unique-server-group-name).\n\n## How LoopBack models map to Oracle tables\n\nThere are several properties you can specify to map the LoopBack models to the existing tables in the Oracle database:\n\n**Model definition** maps to Oracle schema/table\n\n- `oracle.schema`: the schema name of the table\n- `oracle.table`: the table name of the model\n\n**Property definition** maps to Oracle column\n\n- `oracle.columnName`: the column name of the property\n- `oracle.dataType`: the type of the column\n\n(Check out more available database settings in the section [Data mapping properties](https://loopback.io/doc/en/lb4/Model.html#data-mapping-properties).)\n\nThe following example model `User` maps to the table `USER` under schema `XE` in the database with its columns:\n\n{% include code-caption.html content=\"/models/user.model.ts\" %}\n\n```ts\n@model({\n  settings: {\n    oracle: {\n      schema: 'XE',\n      table: 'USER'\n    }\n  }\n})\nexport class User extends Entity {\n  @property({\n    type: 'number',\n    required: true,\n    id: true,\n    oracle: {\n      columnName: 'ID',\n      dataType: 'NUMBER',\n      nullable: 'N'\n    },\n  })\n  id: number;\n\n  @property({\n    type: 'string',\n    required: true,\n    oracle:{\n      columnName: 'LOCALTIONID',\n      dataType: 'VARCHAR2',\n      nullable: 'N'\n    }\n  })\n  locationId: string;\n```\n\n\u003cdetails\u003e\u003csummary markdown=\"span\"\u003e\u003cstrong\u003eFor LoopBack 3 users\u003c/strong\u003e\u003c/summary\u003e\n\n{% include code-caption.html content=\"/common/models/model.json\" %}\n\n```javascript\n{\n    \"name\":\"User\",\n    \"options\":{\n      \"idInjection\":false,\n      \"oracle\":{\n        \"schema\":\"XE\",\n        \"table\":\"USER\"\n      }\n    },\n    \"properties\":{\n      \"myId\":{\n        \"type\":\"number\",\n        \"required\":true,\n        \"id\":1,\n        \"oracle\":{\n          \"columnName\":\"MYID\",\n          \"dataType\":\"NUMBER\",\n        }\n      },\n      \"locationId\":{\n        \"type\":\"String\",\n        \"required\":true,\n        \"length\":20,\n        \"id\":2,\n        \"oracle\":{\n          \"columnName\":\"LOCATION_ID\",\n          \"dataType\":\"VARCHAR2\",\n          \"dataLength\":20,\n          \"nullable\":\"N\"\n        }\n      },\n    }\n  }\n```\n\n\u003c/details\u003e\n\n**Notice**: the Oracle database default type is UPPERCASE. If the oracle settings are not specified in the model, for example:\n\n```ts\nexport class Demo extends Entity {\n  @property({\n    type: 'number',\n    required: true,\n    id: true,\n  })\n  id: number;\n```\n\nthe connector would look for a table named `DEMO` under the default schema in the database and also map the id property to a column named `ID` in that table. This might cause errors if the default table/colum name doesn't exist. Please do specify the settings if needed.\n\n### Configure a custom table/column name\n\nOn the other hand, such settings would also allow you to have different names for models and tables. Take the `User` model as an example, we can map the `User` model to the table `MYUSER` and map the `id` property to column `MY_ID`as long as they are specified correctly:\n\n```ts\n@model({\n  settings: {\n    oracle: {\n      schema: 'XE',\n      table: 'MYUSER' // customized name\n    }\n  }\n})\nexport class User extends Entity {\n  @property({\n    type: 'number',\n    required: true,\n    id: true,\n    oracle: {\n      columnName: 'MYID' // customized name\n    },\n  })\n  id: number;\n  //...\n```\n\n\u003cdetails\u003e\u003csummary markdown=\"span\"\u003e\u003cstrong\u003eFor LoopBack 3 users\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\n{\n    \"name\":\"User\",\n    \"options\":{\n      \"idInjection\":false,\n      \"oracle\":{\n        \"schema\":\"XE\",\n        \"table\":\"MYUSER\" // customized name\n      }\n    },\n    \"properties\":{\n      \"id\":{\n        \"type\":\"number\",\n        \"required\":true,\n        \"id\":1,\n        \"oracle\":{\n          \"columnName\":\"MYID\", // customized name\n          \"dataType\":\"NUMBER\",\n        }\n      },\n      //...\n    }\n  }\n```\n\n\u003c/details\u003e\n\n### Type mapping\n\nSee [LoopBack 4 types](http://loopback.io/doc/en/lb4/LoopBack-types.html) (or [LoopBack 3 types](http://loopback.io/doc/en/lb3/LoopBack-types.html)) for\ndetails on LoopBack's data types.\n\n#### JSON to Oracle Types\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth width=\"450\"\u003eLoopBack Type\u003c/th\u003e\n      \u003cth width=\"450\"\u003eOracle Type\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eString\u003cbr\u003eJSON\u003cbr\u003eText\u003cbr\u003edefault\u003c/td\u003e\n      \u003ctd\u003eVARCHAR2\n      \u003cbr/\u003eDefault length is 1024\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eNumber\u003c/td\u003e\n      \u003ctd\u003eNUMBER\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eDate\u003c/td\u003e\n      \u003ctd\u003eDATE\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eTimestamp\u003c/td\u003e\n      \u003ctd\u003eTIMESTAMP(3)\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eBoolean\u003c/td\u003e\n      \u003ctd\u003eCHAR(1)\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n#### Oracle Types to JSON\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth width=\"450\"\u003eOracle Type\u003c/th\u003e\n      \u003cth width=\"450\"\u003eLoopBack Type\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eCHAR(1)\u003c/td\u003e\n      \u003ctd\u003eBoolean\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eCHAR(n)\u003cbr\u003eVARCHAR\u003cbr\u003eVARCHAR2,\u003cbr\u003eLONG VARCHAR\u003cbr\u003eNCHAR\u003cbr\u003eNVARCHAR2\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eLONG, BLOB, CLOB, NCLOB\u003c/td\u003e\n      \u003ctd\u003eNode.js \u003ca class=\"external-link\" href=\"http://nodejs.org/api/buffer.html\"\u003eBuffer object\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eNUMBER\u003cbr\u003eINTEGER\u003cbr\u003eDECIMAL\u003cbr\u003eDOUBLE\u003cbr\u003eFLOAT\u003cbr\u003eBIGINT\u003cbr\u003eSMALLINT\u003cbr\u003eREAL\u003cbr\u003eNUMERIC\u003cbr\u003eBINARY_FLOAT\u003cbr\u003eBINARY_DOUBLE\u003cbr\u003eUROWID\u003cbr\u003eROWID\u003c/td\u003e\n      \u003ctd\u003eNumber\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eDATE\u003cbr\u003eTIMESTAMP\u003c/td\u003e\n      \u003ctd\u003eDate\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Discovery and auto-migration\n\n### Model discovery\n\nThe Oracle connector supports _model discovery_ that enables you to create LoopBack models based on an existing database schema. Once you defined your datasource:\n\n- LoopBack 4 users could use the commend\n  [`lb4 discover`](https://loopback.io/doc/en/lb4/Discovering-models.html) to\n  discover models.\n- For LB3 users, please check\n  [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).\n  (See\n  [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels)\n  for related APIs information)\n\n### Auto-migration\n\nThe Oracle connector also supports _auto-migration_ that enables you to create a database schema\nfrom LoopBack models.\n\nFor example, based on the following model, the auto-migration method would create/alter existing `CUSTOMER` table under `XE` schema in the database. Table `CUSTOMER` would have two columns: `NAME` and `ID`, where `ID` is also the primary key, and its value would be generated by the database as it has `type: 'Number'` and `generated: true` set:\n\n```ts\n@model()\nexport class Customer extends Entity {\n  @property({\n    id: true,\n    type: 'Number',\n    generated: true\n  })\n  id: number;\n\n  @property({\n    type: 'string'\n  })\n  name: string;\n}\n```\n\n\u003cdetails\u003e\u003csummary markdown=\"span\"\u003e\u003cstrong\u003eFor LoopBack 3 users\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\n{\n    \"name\":\"Customer\",\n    \"options\":{\n      \"idInjection\":false,\n    },\n    \"properties\":{\n      \"id\":{\n        \"type\":\"number\",\n        \"required\":true,\n        \"id\":1,\n      },\n      \"name\":{\n        \"type\":\"string\",\n        \"required\":false,\n      },\n    }\n  }\n```\n\n\u003c/details\u003e\n\nLoopBack Oracle connector creates the following schema objects for a given model:\n\n- A table, for example, PRODUCT\n- A sequence for the primary key, for example, PRODUCT_ID_SEQUENCE\n- A trigger to generate the primary key from the sequence, for example, PRODUCT_ID_TRIGGER\n\n#### Specifying database schema definition via model\n\nBy default, table and column names are generated in uppercase.\n\nBesides the basic model metadata, you can also to specify part of the database schema definition via the\nproperty definition then run the migration script. They will be mapped to the database. The setting is the same as what we introduced in the section [Configure a custom table/column name](#configure-a-custom-table/column-name). One just needs to create models first, then run the migration script.\n\nFor how to run the script and more details:\n\n- For LB4 users, please check [Database Migration](https://loopback.io/doc/en/lb4/Database-migrations.html)\n- For LB3 users, please check [Creating a database schema from models](https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html)\n- Check discovery/migration section the Oracle tutorial\n\n(See [LoopBack auto-migrate method](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-automigrate) for related APIs information)\n\nHere are some limitations and tips:\n\n- If you defined `generated: true` in the id property, it generates **integers** by default. The Oracle connector does not support other auto-generated id types yet. Please check the [Auto-generated ids](#auto-generated-ids) section below if you would like use auto-generated id in different types such as uuid.\n- Only the id property supports the auto-generation setting `generated: true` for now\n- Destroying models may result in errors due to foreign key integrity. First delete any related models by calling delete on models with relationships.\n\n#### Auto-generated ids\n\nAuto-migrate supports the automatic generation of property values for the id property. For Oracle, the default id type is **integer**. Thus if you have `generated: true` set in the id property definition, it generates integers by default:\n\n```ts\n{\n  id: true,\n  type: 'Number',\n  required: false,\n  generated: true // enables auto-generation\n}\n```\n\nIt might be a case to use UUIDs as the primary key in Oracle instead of integers. You can enable it with either the following ways:\n\n- use uuid that is **generated by your LB application** by setting [`defaultFn: uuid`](https://loopback.io/doc/en/lb4/Model.html#property-decorator):\n\n```ts\n  @property({\n    id: true,\n    type: 'string'\n    defaultFn: 'uuid',\n    // generated: true,  -\u003e not needed\n  })\n  id: string;\n```\n\n- alter the table to use Oracle built-in uuid functions (`SYS_GUID()` for example):\n\n```ts\n  @property({\n  id: true,\n  type: 'String',\n  required: false,\n  // settings below are needed\n  generated: true,\n  useDefaultIdType: false,\n})\n  id: string;\n```\n\nThen you will need to alter the table manually.\n\n## Running tests\n\n### Own instance\n\nIf you have a local or remote Oracle instance and would like to use that to run the test suite, use the following command:\n\n- Linux\n\n```bash\nORACLE_HOST=\u003cHOST\u003e ORACLE_PORT=\u003cPORT\u003e ORACLE_USER=\u003cUSER\u003e ORACLE_PASSWORD=\u003cPASSWORD\u003e ORACLE_DATABASE=\u003cDATABASE\u003e npm test\n```\n\n- Windows\n\n```bash\nSET ORACLE_HOST=\u003cHOST\u003e\nSET ORACLE_PORT=\u003cPORT\u003e\nSET ORACLE_USER=\u003cUSER\u003e\nSET ORACLE_PASSWORD=\u003cPASSWORD\u003e\nSET ORACLE_DATABASE=\u003cDATABASE\u003e\nnpm test\n```\n\n### Docker\n\nIf you do not have a local Oracle instance, you can also run the test suite with very minimal requirements.\n\n- Assuming you have [Docker](https://docs.docker.com/engine/installation/) installed, run the following script which would spawn an Oracle instance on your local machine:\n\n```bash\nsource setup.sh \u003cHOST\u003e \u003cPORT\u003e\n```\n\nwhere `\u003cHOST\u003e`, `\u003cPORT\u003e`, `\u003cUSER\u003e`, and `PASSWORD` are optional parameters. The default values are `localhost`, `1521`, `admin`, and `0raclep4ss` respectively. The `DATABASE` setting is always `XE`.\n\n- Run the test:\n\n```bash\nnpm test\n```\n","funding_links":[],"categories":["Enterprise Connectors"],"sub_categories":["Third Party"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-oracle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopbackio%2Floopback-connector-oracle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-oracle/lists"}