Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xadillax/hb-database-scripter
The database upgrade script executer.
https://github.com/xadillax/hb-database-scripter
Last synced: 29 days ago
JSON representation
The database upgrade script executer.
- Host: GitHub
- URL: https://github.com/xadillax/hb-database-scripter
- Owner: XadillaX
- License: gpl-2.0
- Created: 2014-09-04T03:20:42.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-07-03T03:26:09.000Z (4 months ago)
- Last Synced: 2024-10-05T01:52:59.613Z (about 1 month ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HB Database Scripter
The database upgrade script executer.
## Useness
Imagine you have several SQLs to execute to upgrade your database or table:
```sql
ALTER TABLE `commoditlow` ADD `buy_link_mobile` TEXT DEFAULT NULL;
ALTER TABLE `boards` ADD `is_commoditlow_board` TINYINT(1) NOT NULL DEFAULT 0;
```You want write down a script which you can run directly:
```sh
$ node script.js
```You may use this module.
## Installation
```sh
$ npm install hb-database-scripter
```## APIs
### Scripter
#### Constructor
```javascript
var Scripter = require("hb-database-scripter");
var scripter = new Scripter(processor);
```Make sure that `processor` is a function which is truelly run your sqls and the arguments are `sql` and a `callback`.
> Eg.
>
> Imagine your project has a global object db, and it may use as below:
>
> ```javascript
> db.query(sql, function(err) { /** do sth... */ });
> ```
>
> Then you can use `db.query.bind(db)` as your processor.#### push
Push your SQLs.
```javascript
scripter.push("ALTER TABLE `commoditlow` ADD `buy_link_mobile` TEXT DEFAULT NULL;");
scripter.push("ALTER TABLE `boards` ADD `is_commoditlow_board` TINYINT(1) NOT NULL DEFAULT 0;");
```#### exec
Execute your SQLs that you pushed parallelly:
```javascript
scripter.exec(function() {
process.exit(0);
});
```## Who Uses This?
+ Huaban.com
+ maybe, you.## Contribution
You're welcome to fork and pull requests!