Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support for MySQL #23

Closed
cvburgess opened this issue May 20, 2019 · 3 comments
Closed

Support for MySQL #23

cvburgess opened this issue May 20, 2019 · 3 comments

Comments

@cvburgess
Copy link
Owner

@cvburgess I use MySQL as the DB. This is knex raw method feature.

Originally posted by @a2exfr in #19 (comment)

@a2exfr
Copy link

a2exfr commented Sep 15, 2019

Hi. This is the way I get batched normalized output not raw. What you think?

import DataLoader from 'dataloader';


export default class Dataloader {
	constructor(knex) {
		this.db = knex;
		this.queries = {};
		this.loader = new DataLoader(rawQueries =>
			Promise.all(rawQueries.map((rawQuery) => this.queries[rawQuery])),
		);
	}

	normalizeDBResult(result) {
		switch (this.db.client.config.client) {
			case 'postgres':
				return result && result.rows;
			case 'mssql':
				return result;
			case 'sqlite3':
				return result;
			case 'mysql':
				return result;
			case 'mysql2':
			case 'oracledb':
			case 'redshift':
			default:
				return result;
		}
	}

	getBatched(query) {
		const queryString = query.toString();
		this.queries[queryString] = query;
		return this.loader.load(queryString).then(result => this.normalizeDBResult(result));
	}

}

@cvburgess
Copy link
Owner Author

Hey there thank you for the help!

Would you mind opening this as a PR so i can more easily see the diff and test it locally?

@cvburgess
Copy link
Owner Author

Fixed in version 1.0! 🎉

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants