Skip to content

Commit

Permalink
Merge branch 'main' of github.com:PedramNavid/dbtpal
Browse files Browse the repository at this point in the history
  • Loading branch information
PedramNavid committed Feb 11, 2023
2 parents 29ec07b + 88785ed commit e336efe
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 6 deletions.
187 changes: 187 additions & 0 deletions doc/dbtpal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
*dbtpal.txt* For NVIM v0.8.0 Last change: 2023 February 11

==============================================================================
Table of Contents *dbtpal-table-of-contents*

- dbtpal.nvim |dbtpal-dbtpal.nvim|
1. ✨Features |dbtpal-✨features|
- ⚡️ Requirements |dbtpal-⚡️-requirements|
- ⚙ Installation |dbtpal-⚙-installation|
- 🙈 Commmads |dbtpal-🙈-commmads|

DBTPAL.NVIM *dbtpal-dbtpal.nvim*

<div class="figure">
<img src="https://raw.githubusercontent.com/PedramNavid/dbtpal/main/assets/dbt%20model%20run.gif" title="fig:"/>
<p class="caption">image</p>
</div>

A Neovim plugin for dbt model editing. The little helper I wish I always had.

==============================================================================
1. ✨Features *dbtpal-✨features*


- Run / test open model, the entire project, or arbitrary selectors
- Async jobs with pop-up command outputs
- Custom dbt filetype with better syntax highlighting
- Disables accidentally modifying sql files in the target folders
- Jump to any `ref` or `source` model using `gf` (go-to-file)
- Telescope Extension to fuzzy-find models
- Automatically detect dbt project folder


I do welcome requests and use-cases, so feel free to reach out on Twitter
(pdrmnv <https://twitter.com/pdrmnvd>) or by creating an issue.

⚡️ REQUIREMENTS *dbtpal-⚡️-requirements*


- Neovim >=0.5.0
- dbt <https://docs.getdbt.com/dbt-cli/installation> >=1.0.0
- plenary.nvim <https://github.com/nvim-lua/plenary.nvim>


⚙ INSTALLATION *dbtpal-⚙-installation*

Install using your favorite plugin manager:

**Using Packer**

>
use {'pdrmnvd/dbtpal',
config = function()
local dbt = require('dbtpal')
dbt.setup {
-- Path to the dbt executable
path_to_dbt = "dbt",
-- Path to the dbt project, if blank, will auto-detect
-- using currently open buffer for all sql,yml, and md files
path_to_dbt_project = "",
-- Path to dbt profiles directory
path_to_dbt_profiles_dir = vim.fn.expand "~/.dbt",
-- Search for ref/source files in macros and models folders
extended_path_search = true,
-- Prevent modifying sql files in target/(compiled|run) folders
protect_compiled_files = true
}
-- Setup key mappings
vim.keymap.set('n', '<leader>drf', dbt.run)
vim.keymap.set('n', '<leader>drp', dbt.run_all)
vim.keymap.set('n', '<leader>dtf', dbt.test)
vim.keymap.set('n', '<leader>dm', require('dbtpal.telescope').dbt_picker)
-- Enable Telescope Extension
require'telescope'.load_extension('dbt_pal')
end,
requires = { { 'nvim-lua/plenary.nvim' }, {'nvim-telescope/telescope.nvim'} }
}
<


🙈 COMMMADS *dbtpal-🙈-commmads*

dbtpal has sensible defaults and can auto-detect project directories based on
the currently open buffer when first run.

Your typical dbt commands are supported in three modes: current model, all
models, and user-specified models. See the sample setup above for some common
mappings.

Commands can be either invoked as vim user-commands or through lua. Lua calls
provide more flexibility if additional arguments are required, but
user-commands work well if all you need is the default behavior, with a single
model selector argument.

*dbtpal-DbtRun*

DbtRun In Lua: `require('dbtpal').run()` Run
the current model


*dbtpal-DbtRunAll*

DbtRunAll In Lua: `require('dbtpal').run_all()`
Run all models in the project


*dbtpal-DbtRunModel*

DbtRunModel In Lua:
`require('dbtpal').run_model('+my_second_dbt_model')`
Run a specific model or selector.
Requires a model selector argument.
Example: `DbtRunModel
+my_second_dbt_model`


*dbtpal-DbtTest*

DbtTest In Lua: `require('dbtpal').test()` Test
the current model


*dbtpal-DbtTestAll*

DbtTestAll In Lua: `require('dbtpal').test_all()`
Test all models in the project


*dbtpal-DbtTestModel*

DbtTestModel In Lua:
`require('dbtpal').test_model('+my_second_dbt_model')`
Test a specific model or selector.
Requires a model selector argument.
Example: `DbtTestModel
+my_second_dbt_model`


*dbtpal-DbtCompile*

DbtCompile In Lua: `require('dbtpal').compile()`
Compile the current model


*dbtpal-DbtBuild*

DbtBuild In Lua: `require('dbtpal').build()`
Build the current model


 CONFIGURATION ~

You can override default configuration options by passing a table to
`setup({})`. See the Installation section for an example

>
require("dbtpal").setup({ ... })
<


The following options are available:

│ Option │ Description │ Default │
│path_to_dbt │Path to the dbt executable │dbt (i.e. dbt in the local path) │
│path_to_dbt_project │Path to the dbt project │"" (auto-detect) │
│path_to_dbt_profiles_dir│Path to dbt profiles directory │"~/.dbt" │
│extended_path_search │Search for ref/source files in macros and models folders│true │
│protect_compiled_files │Prevent modifying sql files in target/(compiled │run) folders │


MISC ~

Log level can be set with `vim.g.dbtpal_log_level` (must be **before**
`setup()`)

Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

vim:tw=78:ts=8:noet:ft=help:norl:
1 change: 1 addition & 0 deletions lua/dbtpal/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local config = require "dbtpal.config"
local M = {}

M.build_path_args = function(cmd, args)
log.trace("dbtpal config: " .. vim.inspect(config.options))
local dbt_path = config.options.path_to_dbt
local dbt_project = config.options.path_to_dbt_project
local dbt_profile = config.options.path_to_dbt_profiles_dir
Expand Down
13 changes: 7 additions & 6 deletions lua/dbtpal/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ M.defaults = {
M.options = {}

function M.setup(options)
options = options or {}
if options.path_to_dbt_project ~= "" then
options.path_to_dbt_project = vim.fn.expand(options.path_to_dbt_project)
end
if options.path_to_dbt_profiles_dir ~= "" then
options.path_to_dbt_profiles_dir = vim.fn.expand(options.path_to_dbt_profiles_dir)
if options ~= nil then
if options.path_to_dbt_project ~= "" then
options.path_to_dbt_project = vim.fn.expand(options.path_to_dbt_project)
end
if options.path_to_dbt_profiles_dir ~= "" then
options.path_to_dbt_profiles_dir = vim.fn.expand(options.path_to_dbt_profiles_dir)
end
end

M.options = vim.tbl_deep_extend("force", M.defaults, options or {})
Expand Down

0 comments on commit e336efe

Please sign in to comment.