Why does a cursor need to be sequential in pagination - pagination

I am building a cursor-based public API and read in various places that the pagination cursor should be sequential.
I use a UUID as PK and was thinking of returning the UUID PK as cursor. As a client can define filter parameters and sort-keys, I think that a UUID as cursor should be sufficient.
Are there more aspects that I am missing?
Appreciate any help
Edit: Maybe my confusion comes from a clients ability to specify sort-keys

Related

Best way to implement ACL with Mongoose

I have my data model already defined and implemented. I can very easily write manually the filter to filter out non-authorized results for the user who sent the query (which would be in the style of: "collection.acl.personId": queryPersonId )
My problem is, where and how should I write this "thing" to be as automatic as possible?
I tried to do it with a custom query and a static method, but did not had any luck on both.
Static method con: I don't want to rewrite all my code to use .then(). I want to keep the current chaining.
Custom query: it simply did not worked, even by following the doc.
Ideal the result would be something like
Model.findWithAcl(filters).lean()
Model.findOneWithAcl(filters).lean()
Note that we are using Typescript. The priority would be to have something working, but having the ability to have a working type would be the second priority right after.
Thanks for any help
Casl mongoose gives a very good way of filtering both results (row level) and fields from collections. Note that it also can be used in the front end.
Great package that works very well with auth0 rights.
https://casl.js.org/v5/en/guide/intro
https://casl.js.org/v5/en/package/casl-mongoose

How do i implement friendship functionality in database using sequelize for social media demo app

I'm building a social media demo app and to add friends functionality to that app.
In database I am thinking about making new table(model in sequelize) which contains user1 id and user2 id and a status with one character (accepted, rejected etc).
I tried implementing it but faced some issue: Now i need to have unique key but for combination of user 1 and user 2 (pair of user1 and user2 id).
How do I implement something like this using sequelize and also I don't think this is the best way to do it, so if you have a better way please let me know, thanks.
Your description is somewhat lacking and missing some components. However it is clear enough to see what you are describing
is a many-to-many (m:m) relationship. It is just that the both sides come from the same table. While not the most common relationship,
neither is it too unusual. Further the resolution is the same as any other m:m. Create another table that has the key to both sides
as foreign keys. There is one slightly unusual twist in that the combination (parent1, parent2)(P1,P2) and the combination (P2,P1)
should be considered the same. This introduces a slight twist to the norm; instead of generating a PK from the the parent columns
the PK will be just be sequence generated (technically the PK is not required unless there are anticipated child tables of it).
We then create a unique index on the ordered pair (P1,P2). So something along the line of:
create table friends( f_id integer generated always as identity
, user_id_1 integer not null
, user_id_2 integer not null
, status varchar(1) not null default 'P'
, friends_since date not null default now()::date
, constraint friends_pk primary key(f_id)
, constraint f2user_1_fk foreign key(user_id_1)
references users(user_id)
, constraint f2user_2_fk foreign key(user_id_2)
references users(user_id)
, constraint cannot_friend_self
check (user_id_1 != user_id_2)
);
--
-- unique index to recognize (P1,P2) = (P2,P1)
create unique index already_friends on friends
( least(user_id_1,user_id_2), greatest(user_id_1,user_id_2) );
See fiddle here for examples. The bi-directional nature of Friends table causes additional complications within the queries. Typically I hide complication within SQL functions. I have also added a couple useful functions. You should be able to uses these as examples. Note, since they are SQL functions you can extract the statement and convert to a parameterized query.
Sorry, I do not know sequelize so I will not guess at the translation, but there seem to be many examples of the internet for all the above.

Hyperlink to a secondary query in the results of an AutoQuery UI using ServiceStack

Firstly, I am amazed at how simple and performant ServiceStack is. Can't believe I've gone without sing this for so long.
I'm especially loving the AutoQuery and Admin feature, but for the life of me, I'm struggling to find documentation on how to extend the response. What I am trying to do is provide a hyperlink in a response to enable navigation right from a row that is returned.
For example, if a list of records are returned from /records, and the primary key (Id field) could actually be a link (ie ABC123) that is its own DTO.
I've noticed the AutoQueryMetadataFeature, so suspect this provides some hints, but very new to the whole solution so any pointers would be very much appreciated.
Cheers
Craig

PouchDB get documents by ID with certain string in them

I would like to get all documents that contain a certain string in them, I can't seem to find a solution for it..
for example I have the following doc ids
vw_10
vw_11
bmw_12
vw_13
bmw_14
volvo_15
vw_16
how can I get allDocs with the string vw_ "in" it?
Use batch fetch API:
db.allDocs({startkey: "vm_", endkey: "vm_\ufff0"})
Note: \ufff0 is the highest Unicode character which is used as sentinel to specify ranges for ordered strings.
You can use PouchDB find plugin API which is way more sophisticated than allDocs IMO for querying. With the PouchDB find plugin, there is a regex search operator which will allow you do exactly this.
db.find({selector: {name: {$regext: '/vw_'}}});
It's in BETA at the time of writing but we are about to ship a production app with it. That's how stable it has been so far. See https://github.com/nolanlawson/pouchdb-find for more on Pouch Db Find
You better have a view with the key you want to search. This ensures that the key is indexed. Otherwise, the search might be too slow.

Subsonic generate table without primary key

I need to generate a table without primary key. Its absolutely neccessary that the table dosen't have primary key. Please help.
It is absolutely necessary for the SubSonic that table contains primary key:)
The following is quoted from the SubSonic docs on conventions:
Primary Keys
If you want to use SubSonic to access your table, you need to have a Primary Key defined for your table. This is good practice in every case and we need it to do certain things with your table. If you don't have a Primary Key defined, your class won't be generated.
If you don't believe us, or if you think this is a silly convention - SubSonic isn't for you.
Is there any reason you cannot use something like sequences?
class Something {
private static final SEQUENCE seq = getDBsequence()
#id
private final long id = seq.newNumber();
private final String whateverData;
}
EDIT:The way I wrote this was kinda dumb because once you reboot the app. you'll get duplicate keys.. You should use a sequence provided by the DB. Sorry about that.
as Adam pointed out this isn't possible. To be honest I can't think of a situation (outside OLAP) where you can't have a PK. Or perhaps you're stuck in a legacy situation - I can dig that.
What you can do to get around it is, as you pointed out, use our querier tools and then you can send the results ToList<>. Updates should work the same way - not sure about inserts though.

Resources