GithubHelp home page GithubHelp logo

qrp's People

Contributors

kylewill0725 avatar

Watchers

 avatar  avatar

qrp's Issues

Database code has awful structure.

Code in review:

qrp/dropDatabase.ts

Lines 63 to 100 in 9c12d2c

export let addItem = async (client: IDatabase<any>, relic: Relic) => {
// Get eraid
const getEraIdQuery = `SELECT * FROM public."RelicEras" WHERE name = $1`;
const insertEraQuery = `INSERT INTO public."RelicEras"(name) VALUES($1) RETURNING id`;
let eraId = insertIfNone(client, [relic.era], getEraIdQuery, insertEraQuery)['id'];
// Get typeid
const getTypeIdQuery = `SELECT * FROM public."RelicTypes" WHERE name = $1`;
const insertTypeQuery = `INSERT INTO public."RelicTypes"(name) VALUES($1) RETURNING id`;
let typeId = insertIfNone(client, [relic.type], getTypeIdQuery, insertTypeQuery)['id'];
// Get ratingid
const getRatingIdQuery = `SELECT * FROM public."RelicRatings" WHERE name = $1`;
const insertRatingQuery = `INSERT INTO public."RelicRatings"(name) VALUES($1) RETURNING id`;
let ratingId = insertIfNone(client, [relic.rating], getTypeIdQuery, insertTypeQuery)['id'];
// Get droptypeid
const getDropTypeIdQuery = `SELECT * FROM public."RelicDropTypes" WHERE name = $1`;
const insertDropTypeQuery = `INSERT INTO public."RelicDropTypes"(name) VALUES($1) RETURNING id`;
let dropTypeId = insertIfNone(client, ["Relic"], getTypeIdQuery, insertTypeQuery)['id'];
// Get itemid
const getItemIdQuery = `SELECT * FROM public."Items" WHERE name = $1`;
const insertItemQuery = `INSERT INTO public."Items"(name) VALUES($1) RETURNING id`;
let itemIds = [];
for (let i in relic.items) {
itemIds.push([insertIfNone(client, [relic.items[i].name], getTypeIdQuery, insertTypeQuery)['id'], relic.items[i].chance]);
}
// Make new relic
const getRelicIdQuery = `SELECT * FROM public."Relics" WHERE eraid = $1 and typeid = $2`;
const insertRelicQuery = `INSERT INTO public."Relics"(eraid, typeid, ratingid, droptypeid) VALUES($1, $2, $3, $4)`;
let relicId = await insertIfNone(client, [eraId, typeId, ratingId, dropTypeId], getRelicIdQuery, insertRelicQuery);
// Make new relicdropinfo
const insertRelicDropInfoQuery = `INSERT INTO public."RelicDropInfo"(relicId, itemid, chance) VALUES($1, $2, $3)`;
for (let i in itemIds) {
await client.none({
text: insertRelicDropInfoQuery,
values: [relicId, i, 0.5]
});
}
console.log('done');
};

PostgreSQL queries are hard coded and the code is very repetitive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.