# syp-model

> Simple yet powerful promise-based database model for Node.js

Latest version **1.0.10** (published 2018-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install syp-model
pnpm add syp-model
yarn add syp-model
bun add syp-model
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2018-11-05 |
| First published | 2018-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 26.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tuhin Paul |
| Maintainers | tuhinpaul |
| Keywords | database, model, simple, promise, promise-based |

## Links

- npm: https://www.npmjs.com/package/syp-model
- Repository: https://github.com/tuhinpaul/syp-model
- Homepage: https://github.com/tuhinpaul/syp-model#readme
- Issues: https://github.com/tuhinpaul/syp-model/issues
- npm.io page: https://npm.io/package/syp-model

## Dependencies (3)

- [mysql](https://npm.io/package/mysql.md) ^2.15.0
- [typescript](https://npm.io/package/typescript.md) ^2.8.3
- [dts-generator](https://npm.io/package/dts-generator.md) ^2.1.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.10 (latest) — 2018-11-05
- 1.0.9 — 2018-02-02
- 1.0.8 — 2018-02-02
- 1.0.7 — 2018-01-21
- 1.0.6 — 2018-01-21
- 1.0.5 — 2018-01-21
- 1.0.4 — 2018-01-17
- 1.0.3 — 2018-01-17
- 1.0.2 — 2018-01-16
- 1.0.1 — 2018-01-16
- 1.0.0 — 2018-01-16

## README

# :heavy_check_mark: syp-model
###### Simple yet powerful model

Simple yet powerful promise-based database model for Node.js

Author: Tuhin Paul
:phone: [Mobile](tel:+1(306)880-5494) :email: [Email](mailto:tuhin.paul@usask.ca)

January 16, 2018

***

Before using the model, you need to provide following configurations using the static Model::config(connectionParameters, modelConf) method:

* connection parameters
* model configurations

Currently, the model works for mysql. Support for other database systems will be added soon.


Example of using static Model::config(connectionParameters, modelConf):

```javascript
/* provide database connection configuration as follows: */
let dbConnConf = {
	"host"               : "<mysql host>",
	"user"               : "<mysql username>",
	"password"           : "<mysql password>",
	"database"           : "<database name>",
	"multipleStatements" : true,
	"pool"               : { "maxConnections": 20, "maxIdleTime": 30}
}

/** you provide the information of the models and corresponding
    tablename and column names to Model::config() method as follows.
    Suppose, following three tables exist in the database:
        users, categories, and currencies. */
let dbConf = {
	"User": {
		"tablename": "users",
		"columns": [
			"id",
			"role_id",
			"name",
			"username",
			"email",
			"password",
			"status",
			"last_login_on"
		]
	},

	"Category": {
		"tablename": "categories",
		"columns": [
			"id",
			"domain_id",
			"name",
			"parent_id",
			"description"
		]
	},

	"Currency": {
		"tablename": "currencies",
		"columns": [
			"id",
			"code",
			"name"
		]
	},
}

/* configuration information before using Model */
Model.config(dbConnConf, modelConf) {
```

After passing the configuration information, you can use the Model class as shown in the following code snippet. Note that we have a table :

```javascript
let data = {}
Model.factory('Category').select()
.then(categories => {
	data['categories'] = categories;
	return Model.factory('Currency').select()
})
.then(currencies => {
	data['currencies'] = currencies;
	
	/* debug page data */
	console.log('Page Data')
	console.log(data)

	/* render() is a custom method I wrote to render a view */
	// suppose I am using PUG (https://pugjs.org/):
	this.render('all-categories', data)
})
.catch(err => {
	/* renderError is a custom method I wrote to render error */
	this.renderError(err);
})
```

---
_Source: https://npm.io/package/syp-model · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
