Coder Social home page Coder Social logo

Inserting a map about crate-dbal HOT 6 CLOSED

crate avatar crate commented on June 27, 2024
Inserting a map

from crate-dbal.

Comments (6)

seut avatar seut commented on June 27, 2024

objects and array column types are unfortunately currently not supported at crate-pdo.
we'll try to add this feature asap and will notify you.
btw. json_encode the map would be wrong anyway because this would result in a json string.

from crate-dbal.

bashilbers avatar bashilbers commented on June 27, 2024

Any thoughts on how it will work when it's done? Do the object and map type work at ORM level?

from crate-dbal.

seut avatar seut commented on June 27, 2024

fixed through 7d6e95f.
I've released 0.0.4 just now.

In your example, following should work now (note the list of data types argument):

$conn->insert('items', [
        $conn->quoteIdentifier('object_column')  => [
            'id' => 1,
            'name' => 'inner object test'
        ]
    ], [\Crate\PDO\PDO::PARAM_OBJECT]);

from crate-dbal.

bashilbers avatar bashilbers commented on June 27, 2024

unfortunately it doesn't work, I get the following exception:

 DBALException: An exception occurred while executing 'INSERT INTO items ("object_column") VALUES (?)' with params [{"id":1,"name":"inner object test"}]:

SQLActionException[Column 'object_column.id' unknown]

I'm on doctrine/dbal 2.3.5 and crate/crate-dbal 0.0.4

update: the insert does work when I set the object_column to DYNAMIC instead of STRICT

from crate-dbal.

seut avatar seut commented on June 27, 2024

hm you're right, the table creation does not work properly, it does not create the map's sub-columns.
will check this.
meanwhile you could work around it by defining the map column type as \Crate\DBAL\Types\MapType::DYNAMIC, so unknown map keys will be created dynamically while inserting.

from crate-dbal.

seut avatar seut commented on June 27, 2024

after I reproduced your problem, I've found the issue:

sub-columns of a MapType must be declared under the name fields not data.
so this map column declaration will work:

$objDefinition = array(
        'type' => \Crate\DBAL\Types\MapType::STRICT,
        'fields' => array(
            new \Doctrine\DBAL\Schema\Column('id',  \Doctrine\DBAL\Types\Type::getType('integer'), array()),
            new \Doctrine\DBAL\Schema\Column('name',  \Doctrine\DBAL\Types\Type::getType('string'), array()),
        ),
    );

from crate-dbal.

Related Issues (20)

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.