Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smooth-code/knex-scripts
Knex utilities to interact with Postgres database 🗄
https://github.com/smooth-code/knex-scripts
create dump knex knexjs load postgres truncate
Last synced: 2 months ago
JSON representation
Knex utilities to interact with Postgres database 🗄
- Host: GitHub
- URL: https://github.com/smooth-code/knex-scripts
- Owner: smooth-code
- License: mit
- Created: 2018-02-06T14:06:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-01T16:44:38.000Z (about 2 years ago)
- Last Synced: 2024-06-22T15:55:41.038Z (4 months ago)
- Topics: create, dump, knex, knexjs, load, postgres, truncate
- Language: JavaScript
- Homepage:
- Size: 908 KB
- Stars: 11
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Knex Scripts
[![Build Status](https://travis-ci.org/smooth-code/knex-scripts.svg?branch=master)](https://travis-ci.org/smooth-code/knex-scripts)
Knex utilities to interact with Postgres database.
```
npm install knex-scripts
```## Command Line Usage
```
Usage: cli [options] [command]Options:
-V, --version output the version number
--docker Use docker.
--docker-service [service] Docker service name, default: "postgres".
--knexfile [path] Specify the knexfile path.
--cwd [path] Specify the working directory.
--env [name] environment, default: process.env.NODE_ENV || development
-h, --help output usage informationCommands:
create Create database.
drop Drop database.
dump Dump database.
load Load database.
check-structure Check structure.
truncate Truncate all tables.
```## Node API Usage
```js
import knex from 'knex'
import { truncate } from 'knex-scripts'
import config from './knexfile'// Truncate all database
truncate({ getKnex: () => knex(config) })
.then(() => console.log('Truncated'))
.catch(console.error)
```## Configuration
```js
// knexfile.js
const config = {
knexScripts: {
docker: false,
structurePath: 'db/structure.sql',
},
development: {
client: 'postgresql',
connection: {
user: 'postgres',
database: 'development',
timezone: 'utc',
},
},
}module.exports = config
```## License
MIT