boss_db:delete() and counters

33 views
Skip to first unread message

David Welton

unread,
Dec 1, 2014, 7:58:20 AM12/1/14
to chica...@googlegroups.com
https://github.com/ChicagoBoss/boss_db/issues/135

The problem is that delete(Something) is used for both regular
records, like "student-132", as well as counters, where it could be
any key.

I think this has some problems, but am not entirely sure what the best
solution is.

1. If you happen to have a counter named "student-1234", it'll get
deleted as well as the record you were trying to eliminate.

2. Since the delete() code tries to infer a type from the string it's
given, it'll crash if it does *not* get something that it can infer a
table name from!

3. I was looking through the various adapters. It looks like mongodb
doesn't even implement the deletion from counters.

Some ideas about what to do:

* Separate counter key deletion from record deletion. This is the
clean thing to do. It breaks backwards compatibility. But honestly,
given #2 above, I'm not sure anyone can have used this successfully
anyway.

* Catch the results from this: {_, TableName, IdColumn, TableId} =
boss_sql_lib:infer_type_from_id(Id) - if it fetches a valid table,
then delete the record; if not, delete the counter key. This means
you can't use keys like 'foo-1234' in your counter.

I think I'd do the clean thing and create a delete_counter function.
Any objections?

--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/

Evgeny M

unread,
Dec 1, 2014, 3:26:15 PM12/1/14
to chica...@googlegroups.com
I'm the one who opened the issue.
The worst thing is that while you can insert a record with arbitrary key into a table, you won't be able to delete it later. 
So even if you create an another function for the counter the problem will still exist.

Imo if you do delete_counter you will have to create a create_counter as well, so that all this 'counter' feature would be an on-demand one. But it could be more complicated than this - a record can have multiple counters, and there's an autogeneration of counter access functions in model definition with -counter(foo_counter) module attribute.






понедельник, 1 декабря 2014 г., 15:58:20 UTC+3 пользователь David Welton написал:

David Welton

unread,
Dec 2, 2014, 4:54:00 AM12/2/14
to chica...@googlegroups.com
> I'm the one who opened the issue.
> The worst thing is that while you can insert a record with arbitrary key
> into a table, you won't be able to delete it later.
> So even if you create an another function for the counter the problem will
> still exist.
>
> Imo if you do delete_counter you will have to create a create_counter as
> well, so that all this 'counter' feature would be an on-demand one. But it
> could be more complicated than this - a record can have multiple counters,
> and there's an autogeneration of counter access functions in model
> definition with -counter(foo_counter) module attribute.

Ah yes, I see... the boss_db functions are not so bad, but the
auto-generated stuff looks quite messy.

Does anyone use it?
Reply all
Reply to author
Forward
0 new messages