https://github.com/capaj/knex-pg-schema-code-gen
generates a knex schema createTable calls from an existing database
https://github.com/capaj/knex-pg-schema-code-gen
Last synced: about 1 year ago
JSON representation
generates a knex schema createTable calls from an existing database
- Host: GitHub
- URL: https://github.com/capaj/knex-pg-schema-code-gen
- Owner: capaj
- License: mit
- Created: 2018-05-19T09:25:17.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-19T14:00:23.000Z (about 8 years ago)
- Last Synced: 2025-06-13T22:05:17.133Z (about 1 year ago)
- Language: JavaScript
- Size: 63.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# knex-pg-schema-code-gen
generates a knex schema createTable calls from your exisitng Postgre database. Useful when you want to start using knex for instrumenting your DB in tests for example.
Sure you could just make a dump of your schema, but if you want to keep changing the DB schema you'd have to either manually change the SQL dump or you'd have to make a new dump every time.
Having the DB instrumentation in JS makes it much more maintainable in the long run.
## Usage
```javascript
import schemaGenerator from './schema-gen'
import knex from 'knex'
const db = knex({
client: 'pg',
connection: {
// your DB connection details here
}
})
const schemaCode = await schemaGenerator(db) // schema is a string with calls for all tables
const schemaCode = await schemaGenerator(db, 'my_uber_table') // optionally you can call with second argument to limit for just one table
```