prohairesisdeprecated

MySQL database class to abstract pooling and prepared statements

Usage no npm install needed!

<script type="module">
  import prohairesis from 'https://cdn.skypack.dev/prohairesis';
</script>

README

Prohairesis

MySQL database class to abstract pooling and prepared statements

Installation

const { Prohairesis } = require('prohairesis');

// create new database instance
const database = new Prohairesis(env.database);

Methods

query

database.query(`
    SELECT
        *
    FROM
        User
    WHERE
        id = @id
`, {
    id: 1,
});

// returns an array of rows found

getOne

database.getOne(`
    SELECT
        *
    FROM
        User
    WHERE
        id = @id
`, {
    id: 1,
});

// returns an object of row found or null if no rows returned

getValue

const username = database.getValue('username', `
    SELECT
        *
    FROM
        User
    WHERE
        id = @id
`, {
    id: 1,
});

// returns value from column specified

execute

const response = database.execute(`
    INSERT INTO User(
        username,
        password
    ) VALUES (
        @username,
        SHA2(@password, 256)
    )
`, {
    username: 'jake',
    password: 'passwordHere',
});

console.log(response); // { insertId: 1, affectedRows: 1, etc... }

exists

const userExists = database.exists(`
    SELECT *
    FROM User
    WHERE id = @id
`, {
    id: 1,
});

console.log(userExists); // true