Skip to content

Always store slug for Services? #981

Discussion options

You must be logged in to vote
const { Client } = require('pg');
const dotenv = require('dotenv');

dotenv.config();

const client = new Client({
    connectionString: process.env.DATABASE_URL,
    ssl: {
        rejectUnauthorized: false
    }
});

client.connect();

client.query('SELECT * FROM services WHERE slug is null', (err, res) => {
    if (err) throw err;
    for (let service of res.rows) {
        let slug = (service.slug || service.name.split(' ').join('').split('.').join('-').split('/').join('_').toLowerCase());
        console.log("Generated slug for", service.name, "-", slug);

        client.query('UPDATE services SET slug = $1 WHERE ID = $2', [slug, service.id], (err, res) => {
            if (err) throw 

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by JustinBack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #961 on January 27, 2021 23:55.