Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Need actual documentation #48

Open
Drarig29 opened this issue Oct 20, 2020 · 12 comments
Open

Need actual documentation #48

Drarig29 opened this issue Oct 20, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@Drarig29
Copy link
Owner

As said here, the library needs more documentation and examples of implementations for the CRUD interface.

@Drarig29
Copy link
Owner Author

Drarig29 commented Oct 20, 2020

Here is a snippet created by @yuvapoojary that I'll need to add in the documentation.

It's an implementation of the CRUD interface which stores all the data in the memory. After that, the memory can be inserted into any kind of database all at once.

Edit: Please use the NPM package named brackets-memory-db instead (cf. brackets-storage repository), it contains a few bug fixes and is maintained.

class InMemoryDatabase {
    constructor() {
        this.data = {
            participant: [],
            stage: [],
            group: [],
            round: [],
            match: [],
            match_game: []
        };
    }

    setData(data) {
        this.data = data;
    }

    makeFilter(partial) {
        return (entry) => {
            let result = true;
            for (const [key, value] of Object.entries(partial)) {
                result = result && entry[key] === value;
            }
            return result;
        };
    }

    reset() {
        this.data = {
            participant: [],
            stage: [],
            group: [],
            round: [],
            match: [],
            match_game: []
        };
    }

    async insert(table, arg) {
        let id = this.data[table].length;

        if (!Array.isArray(arg)) {
            try {
                this.data[table].push({ id, ...arg });
            }
            catch (error) {
                return -1;
            }
            return id;
        }

        try {
            arg.map(object => {
                this.data[table].push({ id: id++, ...object });
            });
        } catch (error) {
            return false;
        }

        return true;
    }

    async select(table, arg) {
        try {
            if (arg === undefined) return this.data[table];
            if (typeof arg === "number") return this.data[table][arg];
            return this.data[table].filter(this.makeFilter(arg)) || null;
        }
        catch (error) {
            return null;
        }
    }

    async update(table, arg, value) {
        if (typeof arg === 'number') {
            try {
                this.data[table][arg] = value;
                return true;
            }
            catch (error) {
                return false;
            }
        }

        const values = this.data[table].filter(this.makeFilter(arg));
        if (!values) return false;

        values.forEach(v => {
            let existing = this.data[table][v.id];
            for (const key in value) {
                existing[key] = value[key];
            }
            this.data[table][v.id] = existing;
        });

        return true;
    }

    async delete(table, filter) {
        const values = this.data[table];
        if (!values) return false;
        const predicate = this.makeFilter(filter);
        const negativeFilter = (value) => !predicate(value);
        this.data[table] = values.filter(negativeFilter);
        return true;
    }
}

@Drarig29
Copy link
Owner Author

Drarig29 commented Mar 9, 2021

Asked here too... #28

@Drarig29
Copy link
Owner Author

And do this: #52

@Drarig29 Drarig29 changed the title More documentation Need actual documentation Nov 26, 2021
@Drarig29 Drarig29 added the enhancement New feature or request label Nov 26, 2021
@Drarig29
Copy link
Owner Author

Fix the README (powers of two needed?, etc.)

@Drarig29
Copy link
Owner Author

Reference to this, or maybe just the schema: #111

@Drarig29
Copy link
Owner Author

Drarig29 commented Mar 16, 2022

Interesting to add in the seeding section: #123 (comment)

About this also: #59

@Drarig29
Copy link
Owner Author

Drarig29 commented Mar 16, 2022

Also this:

// In this context, a `null` value is not a BYE, but a TDB (to be determined)
// because we consider the tournament might have been started.
// If it's not and you prefer BYEs, just recreate the tournament.

@Drarig29
Copy link
Owner Author

Drarig29 commented Apr 5, 2022

Needs a word about this decision: #133

@Drarig29
Copy link
Owner Author

Interesting questions here: #144

Should be answered in the docs

@versile2
Copy link

More documentation would be great. I love the libraries but dislike having to read the code of each class to figure out what everything does. I'm still chasing what the seeding options mean, as well as the proper options for round robin.

@Drarig29
Copy link
Owner Author

Hey, that's true. In the meantime, what you better need to read are the unit tests. Not the code.

The unit tests document the code 😉

@versile2
Copy link

You are correct, unit tests were a lot easier. That doesn't change the fact it would be nice to have finished Documentation for such a wonderful group of projects :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants