This extension allows you to develop your Oracle (PL/SQL) project in Visual Studio Code. It enables you to:
- Manage PL/SQL source code with version control (Git)
- Compile files and Run statements with ORA errors problem matching
- Package files into a single SQL deployment script
- Deploy to multiple environments in one click
./deploy Deployment package
./scripts SQL Scripts (DDL, DML, files, etc)
./src Source with PL/SQL objects (FUNCTIONS, PACKAGES, PROCEDURES, TABLES, TRIGGERS, TYPES, VIEWS)
./test Unit tests
dbconfig.json DB environment configuration (required)
oradewrc.json Workspace configuration
Setup
Initialize Workspace/Version
- Create configuration files:dbconfig.json
andoradewrc.json
, create workspace folder structure and initialize git repository when starting from scratch (new workspace). Clear logs, package and scripts: prepare workspace for a new version/feature when executed in a non-empty workspace.Import All Source from DB
- Create Source files from DB objects
Build
Toggle Compile Watch
New - Start/End compilaton on save. Compile working tree automatically whenever a Source file changes.Compile Changes to DB
(F6) - Compile changed Source objects (working tree) to DBCompile Current File
- Compile Source object (or any file with a single SQL or PL/SQL statement)Run Current File as Script
(F5) - Execute a SQL script (with SQLPlus)Run Selected Statement
(Ctrl+Enter) - Execute a SQL query or PL/SQL statement with autoCommit and dbms_output enabled
Install
Package Delta
New (Shift+F9) - Package current version changes. Command extracts changed file paths from Git history - starting from latest tagged commit (last version) up to the last commit (HEAD), and then generates SQL deployment script from those paths, TODO and BOL file.Package
(F9) - Generate SQL deployment script, TODO and BOL file.Deploy
- Run SQL deployment script on selected environment (with SQLPlus). Command prompts with environment selection.
Import Changes from DB
(Shift+F6) - Walk Source files and import DB object content if changed on DBImport Current File
Import Selected Object
- Import new object from DB into a Source fileCompile All Source to DB
Run tests
- Execute unit test files that are saved in the workspaceGenerate...
Generate PL/SQL code with a code generator
Set DB Environment
- Set DB environment that is used for executing DB commands. Pick list is generated fromdbconfig.json
. The default value isDEV
.Clear DB Environment
- Set DB environment to<None>
. This means that you choose DB environment every time you execute DB command.
Only dbconfig.json
file is required for the workspace activation and successful connection with your database. Multiple DB environments with multi-users per environment are supported. A minimal example with DEV
environment and a single schema user follows:
{
"DEV": {
"connectString": "localhost/orclpdb",
"users": [{ "user": "hr", "password": "welcome" }]
}
}
Create dbconfig.json
manually in the root folder of your workspace or execute Init Workspace/Version
command.
Workspace supports a base configuration file (oradewrc.json
) and an additional configuration file for each environment (oradewrc.DEV.json
, oradewrc.TEST.json
, etc.). The base configuration settings apply to all environments, unless an environment specific configuration file exists that extends the base.
Default values will be used in the case workspace configuration file is not present. The following settings are available (defaults):
{
"package.input": [
"./scripts/**/initial*.sql",
"./src/**/VIEWS/*.sql",
"./src/**/TYPES/*.sql",
"./src/**/TYPE_BODIES/*.sql",
"./src/**/TRIGGERS/*.sql",
"./src/**/PACKAGES/*.sql",
"./src/**/PACKAGE_BODIES/*.sql",
"./src/**/FUNCTIONS/*.sql",
"./src/**/PROCEDURES/*.sql",
"./scripts/**/final*.sql"
],
"package.exclude": ["./scripts/**/+(file|run)*.sql"],
"package.output": "./deploy/Run.sql",
"package.encoding": "utf8",
"package.templating": false,
"source.input": ["./src/**/*.sql"],
"compile.warnings": "NONE",
"compile.force": false,
"compile.stageFile": true,
"version.number": "0.0.1",
"version.description": "New feature",
"version.releaseDate": "2099-01-01",
"test.input": ["./test/**/*.test.sql"],
"import.getDdlFunction": "dbms_metadata.get_ddl"
}
package.input
- Array of globs for packaging files into deployment script file (package.output).Package Delta
command populates it with changed file paths.package.output
- Deployment script file path. Created witshPackage
commands from concatenated input files and prepared for SQLPlus execution. (wrapped with "SPOOL deploy.log", "COMMIT;", etc )package.exclude
- Array of globs for excluding files from packaging. Scripts that start with "file" or "run" by default.package.encoding
- Encoding of deployment script file. (ex.: "utf8", "win1250", ...) The default value isutf8
.package.templating
- Turn on templating of config variables. Use existing ('${config["version.releaseDate"]}') or declare a new variable in config file and than use it in your sql file. Variables are replaced with actual values during packaging. The default value isfalse
.source.input
- Glob pattern for Source files. Used by generalCompile
andImport
commands to match files that are targeted. For example, to compile only "HR" schema and exclude "HR" tables, set: ["./src/HR/**/.sql", "!./src/HR/TABLES/.sql"].compile.warnings
- PL/SQL compilation warning scopes. The default value isNONE
.compile.force
- Conflict detection. If object you are compiling has changed on DB (has a different DDL timestamp), you are prevented from overriding the changes with a merge step. Resolve merge conflicts if necessary and than compile again. Set totrue
to compile without conflict detection. The default value isfalse
.compile.stageFile
- Automatically stage file after is succesfully compiled (git add). Default value istrue
.version.number
- Version numberversion.description
- Version descriptionversion.releaseDate
- Version release datetest.input
- Array of globs for matching test files. Executed withRun tests
command.import.getDdlFunction
- Custom Get_DDL function name. Use your own DB function to customize import of object's DDL. It is used byImport
commands. The default value isDBMS_METADATA.GET_DDL
.-- Example of a DB function specification: FUNCTION CustomGetDDL(object_type IN VARCHAR2, name IN VARCHAR2, schema IN VARCHAR2 DEFAULT NULL) RETURN CLOB;
Write a PL/SQL function on database, add a definition to configuration file (oradewrc-generate.json
) and then use Generate...
command to execute your generator. A new file with the generated content will be created in your workspace.
The generator function on DB has to have the following specification (parameters):
FUNCTION updateStatement(
object_type IN VARCHAR2, -- derived from path of currently open ${file}
name IN VARCHAR2, -- derived from path of currently open ${file}
schema IN VARCHAR2, -- derived from path of currently open ${file}
selected_object IN VARCHAR2 -- ${selectedText} in editor
) RETURN CLOB;
Function parameters are derived from currently opened file and selected text in your editor when the generator is executed. The first three parameters (object_type
, name
, schema
) are deconstructed from the path of the currently opened ${file} as ./src/${schema}/${object_type}/${name}.sql
, whereas selected_object
is the currently ${selectedText} in editor.
Create a configuration file oradewrc-generate.json
in your workspace root with a definiton:
"generator.define": [
{
"label": "Update Statement",
"function": "utl_generate.updateStatement",
"description": "Generate update statement for a table"
}
]
The label
and function
properties are required for a generator to be succesfully defined (description
is optional). Use output
property to specify a file path of the generated content (also optional). If the output
is omitted a file with unique filename will be created in ./scripts directory.
NOTE: Generators have a separate repository over here: Oradew Code Generators. Your contributions are welcomed!
- Node.js 6, 8, 10 or 11
- Git
- SQLPlus
Extension uses Oracle driver (node-oracledb v3.1.1) that includes pre-built binaries for Node 6, 8, 10 and 11 on: Windows 64-bit (x64), macOS 64-bit (Intel x64) and Linux 64-bit (x86-64) (built on Oracle Linux 6).
For other environments, please refer to INSTALL (Oracle) on building from source code.
- Language PL/SQL
- oracle-format
- SQLTools
- GitLens
- Numbered bookmarks
- Better comments
- Multiple clipboards
You can execute Oradew commands (gulp tasks) directly from the command line (CLI).
# From the extension folder %USERPROFILE%/.vscode/extensions/mp.oradew-vscode-...
> npm run install-cli
This will install oradew
command globally.
If you are installing from the repository you must first compile the source code:
> git clone https://github.com/mickeypearce/oradew-vscode
> npm install && npm run compile && npm run install-cli
# (Use `oradew <command> --help` for command options.)
> oradew --help
Usage: oradew <command> [options]
Commands:
init [options] Initialize a new workspace
create [options] Import All Objects from Db to Source
compile [options] Compile Source files to DB
import [options] Import Source files from DB
package [options] Package files to deployment script
deploy|run [options] Run script (with SQLPlus)
test [options] Run unit tests
generate [options] Code generator
watch [options] Compile when Source file changes
# Create simple dbconfig file and run "Hello World" on DEV environment
> echo {"DEV": {"connectString": "localhost/orclpdb", "users": [{"user": "hr", "password": "welcome"}]}} > dbconfig.json
> oradew compile --object "select 'world' as hello from dual"
# Simple Dev Workflow
> oradew watch
> oradew package
> oradew deploy --env TEST