# mfd

> Simple, object-based interaction with SQL.

Latest version **1.0.3** (published 2018-03-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install mfd
pnpm add mfd
yarn add mfd
bun add mfd
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-03-01 |
| First published | 2018-02-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Robert Coe |
| Maintainers | voces |
| Keywords | mysql, sql, orm |

## Links

- npm: https://www.npmjs.com/package/mfd
- Repository: https://github.com/voces/mfd
- Homepage: https://github.com/voces/mfd#readme
- Issues: https://github.com/voces/mfd/issues
- npm.io page: https://npm.io/package/mfd

## Dependencies (2)

- [mysql2](https://npm.io/package/mysql2.md) ^1.5.1
- [@std/esm](https://npm.io/package/@std/esm.md) ^0.20.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-03-01
- 1.0.2 — 2018-03-01
- 1.0.1 — 2018-02-09
- 1.0.0 — 2018-02-09

## README

# mfd
Simple, object-based interaction with SQL.

## Examples

### Schema
```MySQL
CREATE TABLE `person` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`first` VARCHAR(128) NULL DEFAULT NULL,
	`last` VARCHAR(128) NOT NULL,
	PRIMARY KEY (`id`)
);
CREATE TABLE `friend` (
	`source` INT(10) UNSIGNED NOT NULL,
	`target` INT(10) UNSIGNED NOT NULL,
	PRIMARY KEY (`source`, `target`),
	INDEX `likedBy` (`target`),
	CONSTRAINT `friends` FOREIGN KEY (`source`) REFERENCES `person` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
	CONSTRAINT `likedBy` FOREIGN KEY (`target`) REFERENCES `person` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
);
```

### Setup
```JavaScript
const MFD = require( "../index.js" );

const mfd = new MFD( {
	host: "localhost",
	user: "test",
	database: "test"
} );
```

### Create
```JavaScript
const tim = new mfd.collections.person( { first: "Tim", last: "Smith" } );
await tim.save();
console.log( ( await mfd.query( "person" ).where( { first: "Tim" } ).execute() )[ 0 ] );

> { id: 6, first: 'Tim', last: 'Smith' }
```

### Read
```JavaScript
mfd.query( "person" )
	.populate( "friends", "friends.target" )
	.where( { $or: [ { "person.first": "Robert" }, { "person.first": "Brad" } ] } )
	.execute()
	.then( results => console.log( results ) ).catch( err => console.error( err ) );

> [ { id: 1,
    first: 'Brad',
    last: 'Hesse',
    friends:
     [ { source: 1,
         target:
          { id: 2,
            first: 'Robert',
            last: 'Coe',
            friends: [ [Object], [Object], [Object] ] } },
       { source: 1, target: { id: 3, first: 'French', last: 'Boy' } },
       { source: 1, target: { id: 4, first: 'James', last: 'Joe' } } ] },
  { id: 2,
    first: 'Robert',
    last: 'Coe',
    friends:
     [ { source: 2,
         target:
          { id: 1,
            first: 'Brad',
            last: 'Hesse',
            friends: [ [Object], [Object], [Object] ] } },
       { source: 2, target: { id: 4, first: 'James', last: 'Joe' } },
       { source: 2,
         target: { id: 5, first: 'Kiefer', last: 'von Gaza' } } ] } ]
```

### Update
```JavaScript
const robert = ( await mfd.query( "person" ).where( { first: "Robert" } ).execute() )[ 0 ];
robert.last = "Coel";
await robert.save();
console.log( ( await mfd.query( "person" ).where( { first: "Robert" } ).execute() )[ 0 ] );

> { id: 2, first: 'Robert', last: 'Coel' }
```

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