Skip to main content

database init

[Plumbing] Create an empty CodeQL database.

Who can use this feature?

CodeQL is available for the following repository types:

Note

This content describes the most recent release of the CodeQL CLI. For more information about this release, see https://github.com/github/codeql-cli-binaries/releases.

To see details of the options available for this command in an earlier release, run the command with the --help option in your terminal.

Synopsis

Shell
codeql database init --source-root=<dir> [--language=<lang>[,<lang>...]] [--github-auth-stdin] [--github-url=<url>] [--extractor-option=<extractor-option-name=value>] <options>... -- <database>

Description

[Plumbing] Create an empty CodeQL database.

Create a skeleton structure for a CodeQL database that doesn't have a raw QL dataset yet, but is ready for running extractor steps. After this command completes, run one or more codeql database trace-command commands followed by codeql database finalize to prepare the database for querying.

(Part of what this does is resolve the location of the appropriate language pack and store it in the database metadata, such that it won't need to be redone at each extraction command. It is not valid to switch extractors in the middle of an extraction operation anyway.)

Options

Primary Options

<database>

[Mandatory] Path to the CodeQL database to create. This directory will be created, and must not already exist (but its parent must).

If the --db-cluster option is given, this will not be a database itself, but a directory that will contain databases for several languages built from the same source root.

It is important that this directory is not in a location that the build process will interfere with. For instance, the target directory of a Maven project would not be a suitable choice.

-s, --source-root=<dir>

[Mandatory] The root source code directory. In many cases, this will be the checkout root. Files within it are considered to be the primary source files for this database. In some output formats, files will be referred to by their relative path from this directory.

--[no-]overwrite

[Advanced] If the database already exists, delete it and proceed with this command instead of failing. If the directory exists, but it does not look like a database, an error will be thrown.

--[no-]force-overwrite

[Advanced] If the database already exists, delete it even if it does not look like a database and proceed with this command instead of failing. This option should be used with caution as it may recursively delete the entire database directory.

--codescanning-config=<file>

[Advanced] Read a Code Scanning configuration file specifying options on how to create the CodeQL databases and what queries to run in later steps. For more details on the format of this configuration file, refer to Customizing your advanced setup for code scanning. To run queries from this file in a later step, invoke codeql database analyze without any other queries specified.

--[no-]db-cluster

Instead of creating a single database, create a "cluster" of databases for different languages, each of which is a subdirectory of the directory given on the command line.

-l, --language=<lang>[,<lang>...]

The language that the new database will be used to analyze.

Use codeql resolve languages to get a list of the pluggable language extractors found on the search path.

When the --db-cluster option is given, this can appear multiple times, or the value can be a comma-separated list of languages.

If this option is omitted, and the source root being analysed is a checkout of a GitHub repository, the CodeQL CLI will make a call to the GitHub API to attempt to automatically determine what languages to analyse. Note that to be able to do this, a GitHub PAT token must be supplied either in the environment variable GITHUB_TOKEN or via standard input using the --github-auth-stdin option.

--build-mode=<mode>

The build mode that will be used to create the database.

Choose your build mode based on the language you are analyzing:

none: The database will be created without building the source root. Available for C#, Java, JavaScript/TypeScript, Python, and Ruby.

autobuild: The database will be created by attempting to automatically build the source root. Available for C/C++, C#, Go, Java/Kotlin, and Swift.

manual: The database will be created by building the source root using a manually specified build command. Available for C/C++, C#, Go, Java/Kotlin, and Swift.

When creating a database with --command, there is no need to additionally specify '--build-mode manual'.

Available since v2.16.4.

--[no-]allow-missing-source-root

[Advanced] Proceed even if the specified source root does not exist.