Git Product home page Git Product logo

ngrest-db's Issues

Problem with adding package with MySQL db option on Mac OS X

Seems like there is a problem when adding ngrest-db package on Mac OS X with the MySQL option. looking through the CMakeLists.txt, it seems that CMAKE_REQUIRED_INCLUDE is not set, so check_include_file_cxx(mysql/mysql.h HAS_MYSQL) will only check the XCode Mac OS X SDK, which does not contain mysql.h nor the PostGRES lib required (but it does contain sqlite3.h, so that option works). I think CMAKE_REQUIRED_INCLUDE should be set by default to "/usr/local/include", so that CMake will search that path for the proper header files.

mysql setting a uniqe constraint on std::string type

I got this error:

#1071 - Specified key was too long; max key length is 767 bytes

from the mysql backend, while trying to set a

//*unique: true
std::string mystring;

on a c++ std::string type.

A quick search got me these results:

Since I needed it in a project I considered few possibilities:

  1. Set innodb_large_prefix, which was introduced in MySQL 5.5.14 and allows you to include columns up to 3072 bytes long in InnoDB indexes.
    Command to the whole db:
set global innodb_large_prefix = ON;

LIMITATION: This might be useful, but it affects all dbs, and I don't know how much overhead it will cost in terms of storage dimensions.

  1. Set a larger prefix to a subset of the column, like so:
ALTER TABLE `mytable` ADD UNIQUE KEY `mystring` ( `mystring`(255) );

It is also possible to do it inside the table creation query, with this code inserted after the fields declaration:

CONSTRAINT mystring UNIQUE (mystring(255))

LIMITATION: This affects only the first 255 bystes, i.e., if there are sequential keys 256 bytes long, and of these the last one only the last one changes, they can't be indexed, because 255 bytes are still the same... this however is a very specific case, not one actually happening any day soon (imho).

  1. Recompile MySqlDb.cpp and change the string limit from 256 to 255 bytes, like so:
    (from line 582)
    static const std::string types[size] = {
        "VOID",
        "TINYINT",
        "INTEGER",
        "BIGINT",
        "DOUBLE",
        "INTEGER",
        "VARCHAR(255)" //changed from "VARCHAR(256)" for InnoDb unique key issues
    };

LIMITATION: This change effectively breacks the compatibility with the postgres backend (which is still 256); however, there is still no compat with sqlite where a text doesn't have a fixed lenght, so it should not be a problem to have default strings larger/shorter in different DB backends. Additionally, it may breack the code somewhere else, because it is setting a more restrictive contraint than there was before (strings shorter by a byte)

Personally, I chose to recompile the code with a VARCHAR(255) because it was the quickest fix to the problem, and since it is my project I don't mind the limitation, as long as i know it's in place.

However I found solution 2 a better option, if it were possible to apply consistently inside the code, upoon table creation (with either of the two methods); the only thing is that it means a larger change to the code, and since I didn't have a chance to study the code better, to see where and how implement the changes, I was afraid of messing up and have code breaking somewhere else. (note aside, it could be useful in this case the snippet of code you put at the end of the README.md, where after creating all tables, you apply changes to them to insert data and set the autoinsertion... it is sufficient to pass a query with the unique key creation there, instead of setting the // *unique: true inside the struct. However, I have an issue, by which the code doesn't get executed, and I don't know if it's my code or a real bug, so for now I didn't try that method)

Anyway, thank you for this project, it's great and really it's solving some serious problems I have (the only other real solution is to use python, or worse java... I like the idea of having some code that I can test in a small server, and then compile as module of apach, so three thumbs up for the great job you did!)

mongoDB

what do you think about adding mongodb, i did some test and it works.

create whole schema

Make possible to create whole schema from DbManager.
Must regard table dependencies (FKs) when creating.

schema migration

Add mechanism to store schema version and upgrade schema using migration, for example, like as android db helper.

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.