postkrebs :/
This commit is contained in:
		@@ -39,24 +39,30 @@ const write = (kat, key, value, type, cb) => {
 | 
			
		||||
    value = JSON.stringify(value);
 | 
			
		||||
 | 
			
		||||
  console.log(kat, key, value, type);
 | 
			
		||||
  sql.any("select * from cfg where class = ? && key = ? limit 1", [kat, key], (err, rows) => {
 | 
			
		||||
    console.log(rows);
 | 
			
		||||
  sql.any("select * from cfg where class = $1 && key = $2 limit 1", [kat, key]).then(rows => {
 | 
			
		||||
    if (rows.length > 0) {
 | 
			
		||||
      sql.any("update cfg set value = ? where class = ? && key = ?", [value, kat, key], (err) => {
 | 
			
		||||
        console.log("updated", err);
 | 
			
		||||
      sql.any("update cfg set value = $1 where class = $2 && key = $3", [value, kat, key]).then(rows => {
 | 
			
		||||
        read().then(() => {
 | 
			
		||||
          if(cb) cb();
 | 
			
		||||
        });
 | 
			
		||||
      })
 | 
			
		||||
      .catch(err => {
 | 
			
		||||
        console.log("on update", err);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      sql.any("insert into cfg (class, key, value, type) values (?, ?, ?, ?)", [kat, key, value, type], (err) => {
 | 
			
		||||
        console.log("inserted", err);
 | 
			
		||||
      sql.any("insert into cfg (class, key, value, type) values ($1, $2, $3, $4)", [kat, key, value, type]).then(rows => {
 | 
			
		||||
        read().then(() => {
 | 
			
		||||
          if (cb) cb();
 | 
			
		||||
        });
 | 
			
		||||
      })
 | 
			
		||||
      .catch(err => {
 | 
			
		||||
        console.log("on insert", err);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
  .then(err => {
 | 
			
		||||
    console.log("on select", err);
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,8 @@ let _query_get = `
 | 
			
		||||
  with ranked_quotes as (
 | 
			
		||||
    select nick,
 | 
			
		||||
      item,
 | 
			
		||||
      rank() over (partition by nick order by id),
 | 
			
		||||
      count(*) over (partition by nick) as total
 | 
			
		||||
      rank() over (partition by lower(nick) order by id),
 | 
			
		||||
      count(*) over (partition by lower(nick)) as total
 | 
			
		||||
    from nxy_quotes
 | 
			
		||||
  )
 | 
			
		||||
  select *
 | 
			
		||||
@@ -43,6 +43,7 @@ module.exports = bot => {
 | 
			
		||||
          sql.any(_query_add, [ nick, quote, `${e.network}.${e.channel}`, e.user.nick ])
 | 
			
		||||
            .then(rows => { })
 | 
			
		||||
            .catch(err => {
 | 
			
		||||
              console.log(err);
 | 
			
		||||
              e.reply("duplicate!");
 | 
			
		||||
            });
 | 
			
		||||
        break;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user