Skip to content

Commit

Permalink
Update project config
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed Apr 29, 2024
1 parent c496b42 commit 4dc702a
Show file tree
Hide file tree
Showing 17 changed files with 723 additions and 150 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/git-leaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: gitleaks
on: [pull_request]
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/linux_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ jobs:
- uses: nao1215/actions-hottest@v1
with:
args: '-cover -coverpkg=./... -coverprofile=coverage.out ./...'

- uses: k1LoW/octocov-action@v1
52 changes: 52 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
run:
go: "1.20"

issues:
exclude-use-default: false

linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- asciicheck
- bodyclose
- dogsled
- durationcheck
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gochecknoinits
- goconst
- gocritic
- goimports
- gosec
- ifshort
- misspell
- nakedret
- noctx
- prealloc
- rowserrcheck
- sqlclosecheck
- stylecheck
- tagliatelle
- thelper
- unconvert
- unparam
- wastedassign
- whitespace
linters-settings:
tagliatelle:
case:
use-field-name: true
rules:
json: snake
16 changes: 16 additions & 0 deletions .octocov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# generated by octocov init
coverage:
if: true
acceptable: 80%
diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
comment:
if: is_pull_request
hideFooterLink: false
summary:
if: true
report:
if: is_default_branch
datastores:
- artifact://${GITHUB_REPOSITORY}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [](https://github.com/nao1215/sqly/compare/v0.5.2...) (2024-04-29)

* Introduce octocov [#44](https://github.com/nao1215/sqly/pull/44) ([nao1215](https://github.com/nao1215))
* Bump github.com/google/wire from 0.5.0 to 0.6.0 [#41](https://github.com/nao1215/sqly/pull/41) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/mattn/go-sqlite3 from 1.14.19 to 1.14.22 [#40](https://github.com/nao1215/sqly/pull/40) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/mattn/go-sqlite3 from 1.14.18 to 1.14.19 [#37](https://github.com/nao1215/sqly/pull/37) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/fatih/color from 1.15.0 to 1.16.0 [#36](https://github.com/nao1215/sqly/pull/36) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/mattn/go-sqlite3 from 1.14.17 to 1.14.18 [#35](https://github.com/nao1215/sqly/pull/35) ([dependabot[bot]](https://github.com/apps/dependabot))
* (auto merged) Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 [#34](https://github.com/nao1215/sqly/pull/34) ([dependabot[bot]](https://github.com/apps/dependabot))
* Add automerged workflows [#33](https://github.com/nao1215/sqly/pull/33) ([nao1215](https://github.com/nao1215))
* Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 [#32](https://github.com/nao1215/sqly/pull/32) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/nao1215/gorky from 0.2.0 to 0.2.1 [#31](https://github.com/nao1215/sqly/pull/31) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/fatih/color from 1.14.1 to 1.15.0 [#30](https://github.com/nao1215/sqly/pull/30) ([dependabot[bot]](https://github.com/apps/dependabot))
* Bump github.com/fatih/color from 1.13.0 to 1.14.1 [#29](https://github.com/nao1215/sqly/pull/29) ([dependabot[bot]](https://github.com/apps/dependabot))
* Change golden pacakge import path [#28](https://github.com/nao1215/sqly/pull/28) ([nao1215](https://github.com/nao1215))
128 changes: 1 addition & 127 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,127 +1 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at GitHub Issue.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
Please approach others with respect. That is everything.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ test: ## Start test
env GOOS=$(GOOS) $(GO_TEST) -cover $(GO_PKGROOT) -coverprofile=cover.out
$(GO_TOOL) cover -html=cover.out -o cover.html

coverage-tree: test ## Generate coverage tree
go-cover-treemap -statements -coverprofile cover.out > doc/img/cover-tree.svg

changelog: ## Generate changelog
ghch --format markdown > CHANGELOG.md

generate: ## Generate code from templates
$(GO) generate ./...

tools: ## Install dependency tools
$(GO_INSTALL) github.com/Songmu/ghch/cmd/ghch@latest
$(GO_INSTALL) github.com/nao1215/hottest@latest
$(GO_INSTALL) github.com/google/wire/cmd/wire@latest
$(GO_INSTALL) github.com/charmbracelet/vhs@latest
$(GO_INSTALL) github.com/nikolaydubina/go-cover-treemap@latest

vet: ## Start go vet
$(GO_VET) $(GO_PACKAGES)

Expand Down
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
[![reviewdog](https://github.com/nao1215/sqly/actions/workflows/reviewdog.yml/badge.svg)](https://github.com/nao1215/sqly/actions/workflows/reviewdog.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/nao1215/sqly)](https://goreportcard.com/report/github.com/nao1215/sqly)
![GitHub](https://img.shields.io/github/license/nao1215/sqly)
# execute SQL against CSV/TSV/LTSV/JSON with shell.
![demo](./doc/demo.gif)
![demo](./doc/img/demo.gif)

**sqly** command imports CSV/TSV/LTSV/JSON file(s) into an in-memory DB and executes SQL against the CSV/TSV/LTSV/JSON. sqly uses [SQLite3](https://www.sqlite.org/index.html) as its DB. So, sql syntax is same as SQLite3.

The sqly command has sqly-shell. You can interactively execute SQL with sql completion and command history. Of course, you can also execute SQL without running the sqly-shell.

# Features
## Features
✅ execute SQL against CSV / TSV / LTSV / JSON.
✅ output SQL result to CSV / TSV / LTSV / JSON file format.
✅ print SQL result in ASCII Table / CSV / TSV / LTSV / JSON file format.
✅ interactive sqly shell with input completion, emacs-keybindings, input history.

# How to install
## How to install
### Use "go install"
If you does not have the golang development environment installed on your system, please install golang from the [golang official website](https://go.dev/doc/install).
```
Expand All @@ -28,16 +27,16 @@ $ go install github.com/nao1215/sqly@latest
※ Main dependency is [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) and gcc.


# How to use
## How to use
sqly command automatically imports the CSV/TSV/LTSV/JSON file into the DB when you pass a CSV/TSV/LTSV/JSON file as an argument. DB table name is the same as the file name (e.g., if you import user.csv, sqly command create the user table)

## Syntax
### Syntax
```
sqly [OPTIONS] [FILE_PATH]
```
※ The sqly option must be specified before the file to be imported.

## --sql option: execute sql in terminal
### --sql option: execute sql in terminal
--sql option takes an SQL statement as an optional argument. You pass file path(s) as arguments to the sqly command. sqly command import them. sqly command automatically determines the file format from the file extension.
```
$ sqly --sql "SELECT user_name, position FROM user INNER JOIN identifier ON user.identifier = identifier.id" testdata/user.csv testdata/identifier.csv
Expand All @@ -50,7 +49,7 @@ $ sqly --sql "SELECT user_name, position FROM user INNER JOIN identifier ON user
+-----------+-----------+
```

## Change output format
### Change output format
sqly command output sql results in ASCII table format, CSV format (--csv option), TSV format (--tsv option), LTSV format (--ltsv option) and JSON format (--json option). This means that conversion between csv and json is supported.
```
$ sqly --sql "SELECT * FROM user LIMIT 2" --csv testdata/user.csv
Expand Down Expand Up @@ -82,10 +81,10 @@ Rachel,1,Booker,booker12
Mary,2,Jenkins,jenkins46
```

## run sqly shell
### run sqly shell
If the --sql option is not specified, the sqly shell is started. When you execute sqly command, it is optional whether or not to specify file(s). The sqly shell functions similarly to a common SQL client (e.g., sqlite3 command or mysql command). sqly shell has helper commands, SQL execution history management and input complement.

### sqly helper command
#### sqly helper command
The command beginning with a dot is the sqly helper command; I plan to add more features in the future to make the sqly shell run more comfortably.
```
$ sqly
Expand All @@ -104,20 +103,20 @@ sqly> .help
.tables: print tables
```

![demo](./doc/shell-demo.png)
![demo](./doc/img/shell-demo.png)

## Output sql result to file
### For linux user
### Output sql result to file
#### For linux user
sqly command can save SQL execution results to a file using shell redirection. The --csv option outputs SQL execution results in CSV format instead of table format.
```
$ sqly --sql "SELECT * FROM user" --csv testdata/user.csv > test.csv
```
### For windows user
#### For windows user
```
$ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
```

# All options
### All options
```
[OPTIONS]
-c, --csv change output format to csv (default: table)
Expand All @@ -131,7 +130,7 @@ $ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
-v, --version print sqly version
```

# Key Binding
### Key Binding
|Key Binding |Description|
|:--|:--|
|Ctrl + A |Go to the beginning of the line (Home)|
Expand All @@ -146,7 +145,8 @@ $ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
|Ctrl + K |Cut the line after the cursor to the clipboard|
|Ctrl + U |Cut the line before the cursor to the clipboard|
|Ctrl + L |Clear the screen|
# Features to be added

## Features to be added
- [x] import json
- [x] print json format
- [x] dump json file
Expand All @@ -172,12 +172,15 @@ $ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
- [ ] Support PostgreSQL driver
- [ ] Unit test coverage 80%

# Limitions (Not support)
## Unit Test Coverage Treemap
![treemap](./doc/img/cover-tree.svg)

## Limitions (Not support)
- DDL such as CREATE
- DML such as GRANT
- TCL such as Transactions

# Contributing
## Contributing
First off, thanks for taking the time to contribute! ❤️ Contributions are not only related to development. For example, GitHub Star motivates me to develop!

[![Star History Chart](https://api.star-history.com/svg?repos=nao1215/sqly&type=Date)](https://star-history.com/#nao1215/sqly&Date)
Expand Down
Loading

0 comments on commit 4dc702a

Please sign in to comment.