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 to support upsert function in Laravel 10 #2718

Closed
zyz954489346 opened this issue Feb 2, 2024 · 1 comment · Fixed by #2877
Closed

Need to support upsert function in Laravel 10 #2718

zyz954489346 opened this issue Feb 2, 2024 · 1 comment · Fixed by #2877

Comments

@zyz954489346
Copy link

zyz954489346 commented Feb 2, 2024

  • Laravel-mongodb Version: 4.1
  • PHP Version: 8.3
  • Database Driver & Version: 4

Description:

The implementation of Cache's put function is modified to db's upsert function in Laravel10.
image

Steps to reproduce

When the driver of cache is changed to mongodb,This will lead to an error. Such as this:

 \Cache::store('mongdb-conn')->forever($key, $val);

// or 
 \Cache::store('mongdb-conn')->put($key, $val);

The error is: This database engine does not support upserts.

@zyz954489346 zyz954489346 changed the title Need to support upsert method in Laravel 10 Need to support upsert function in Laravel 10 Feb 2, 2024
@GromNaN
Copy link
Member

GromNaN commented Feb 8, 2024

Thanks for reporting this issue. It's tracked in Jira: PHPORM-141

GromNaN added a commit that referenced this issue Apr 22, 2024
Fix fo PHPORM-99

In theory, we can use DatabaseStore and DatabaseLock. But various issues prove the changing nature of their implementation, based on new features in the query builder, make this feature unstable for MongoDB users. fix #2718, fix #2609

By introducing dedicated drivers, we can optimize the implementation to use the mongodb library directly instead of the subset of features provided by Laravel query builder.

Usage:

# config/cache.php
return [

    'stores' => [

        'mongodb' => [
            'driver' => 'mongodb',
            'connection' => 'mongodb',
            'collection' => 'cache',
            'lock_connection' => 'mongodb',
            'lock_collection' => 'cache_locks',
            'lock_lottery' => [2, 100],
            'lock_timeout' => '86400',
        ]
    ]

]
Cache:

// Store any value into the cache. The value is serialized in MongoDB
Cache::set('foo', [1, 2, 3]);

// Read the value
dump(Cache::get('foo'));

// Clear the cache
Cache::flush();
Lock:

// Get an unique lock. It's very important to keep this object in memory
// so that the lock can be released.
$lock = Cache::lock('foo');
$lock->block(10); // Wait 10 seconds before throwing an exception if the lock isn't released

// Any time-consuming task
sleep(5);

// Release the lock
$lock->release();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants