Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Thorsten Jolitz
Henrik Sarvell hsarv...@gmail.com
writes:

Hi Henrik,

 why do you want to do this explicitly since it's done for
 you implicitly in all the various type of reference relations you have
 (typically +Link)?

I want to export the objects to a textual representation that might be
edited and then committed again, so I must be able to find out which DB
object is associated to the textual representation. 

 In Macropis I simply use the convention of having a relation called id
 auto increment (by way of http://software-lab.de/doc/refG.html#genKey )
 , that way it doesn't matter which machine something is on, I will
 never have to worry since something like the action /+Page/update/3/
 always updates the object of class +Page with id 3 no matter what the
 {x...} location might look like.

That sounds like a solution I should copy. Just out of curiosity: in a
distributed database, the object ids ({3}, {1-2} ...) are not unique but
might be repeated on different machines?

 However the impetus for this convention was actually the fact that
 functions like db and collect need for instance a +Ref or +Key to be
 able to fetch an object at all, having a +Key called id in all objects
 make things so much easier.

I figured that out too (- db and collect need a +Ref or +Key) and it
makes using a +Key id even more reasonable, I wasn't aware of the id
functions in picolisp, so I thought about my own solution. 

 But anyway, to really answer your question you might want to look
 into: http://software-lab.de/doc/refI.html#id

 And as far as the remote stuff goes with the db id and obj id combo
 AFAIK you have to implement it yourself, you might want to start by
 reading this discussion:
 http://comments.gmane.org/gmane.lisp.picolisp.general/2849

Thanks for the tips, very helpful!


 On Sun, Jan 26, 2014 at 6:56 PM, Thorsten Jolitz
 tjol...@gmail.com wrote:

 Thorsten Jolitz tjol...@gmail.com
 writes:
 
 ,--
 ---
 | Sorry, I sent this post accidentally before I was finished, so I
 have to
 | send it again.
 `--
 ---
 
 
 
 Hi List,
 
 say I want to use the internal Object ID of database object as a
 unique string
 identifier (useful e.g. for export in a textformat), i.e.
 something
 like:
 
 
 ,-
 
 | : (put '{33} 'ID {33})
 
 `-
 
 how do I get the ID from a database object in a program? And is
 there
 some unique identifier for a database too, so that object-id and
 db-id
 could be combined into a globally unique id?
 
 
 
 
 --
 cheers,
 Thorsten
 
 --
 UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
 



-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Henrik Sarvell

 That sounds like a solution I should copy. Just out of curiosity: in a
 distributed database, the object ids ({3}, {1-2} ...) are not unique but
 might be repeated on different machines?


AFAIK yes. In any case the {x...} locations are changed by the remote
functionality to avoid clashes with local objects, ie a remote object won't
have the same {x...} as it has locally on the remote machine.

This fact could be used in the creation of functions that handle remote
objects more or less transparently, a typical example would the the get
algo, let's say I do (;; Trans user) and Trans is a remote object then the
;; function infers that fact and fetches the user from the remote machine
through the local +Link pointer on that machine.




On Mon, Jan 27, 2014 at 3:16 PM, Thorsten Jolitz tjol...@gmail.com wrote:

 Henrik Sarvell hsarv...@gmail.com
 writes:

 Hi Henrik,

  why do you want to do this explicitly since it's done for
  you implicitly in all the various type of reference relations you have
  (typically +Link)?

 I want to export the objects to a textual representation that might be
 edited and then committed again, so I must be able to find out which DB
 object is associated to the textual representation.

  In Macropis I simply use the convention of having a relation called id
  auto increment (by way of http://software-lab.de/doc/refG.html#genKey )
  , that way it doesn't matter which machine something is on, I will
  never have to worry since something like the action /+Page/update/3/
  always updates the object of class +Page with id 3 no matter what the
  {x...} location might look like.

 That sounds like a solution I should copy. Just out of curiosity: in a
 distributed database, the object ids ({3}, {1-2} ...) are not unique but
 might be repeated on different machines?

  However the impetus for this convention was actually the fact that
  functions like db and collect need for instance a +Ref or +Key to be
  able to fetch an object at all, having a +Key called id in all objects
  make things so much easier.

 I figured that out too (- db and collect need a +Ref or +Key) and it
 makes using a +Key id even more reasonable, I wasn't aware of the id
 functions in picolisp, so I thought about my own solution.

  But anyway, to really answer your question you might want to look
  into: http://software-lab.de/doc/refI.html#id
 
  And as far as the remote stuff goes with the db id and obj id combo
  AFAIK you have to implement it yourself, you might want to start by
  reading this discussion:
  http://comments.gmane.org/gmane.lisp.picolisp.general/2849

 Thanks for the tips, very helpful!


  On Sun, Jan 26, 2014 at 6:56 PM, Thorsten Jolitz
  tjol...@gmail.com wrote:
 
  Thorsten Jolitz tjol...@gmail.com
  writes:
 
  ,--
  ---
  | Sorry, I sent this post accidentally before I was finished, so I
  have to
  | send it again.
  `--
  ---
 
 
 
  Hi List,
 
  say I want to use the internal Object ID of database object as a
  unique string
  identifier (useful e.g. for export in a textformat), i.e.
  something
  like:
 
 
  ,-
 
  | : (put '{33} 'ID {33})
 
  `-
 
  how do I get the ID from a database object in a program? And is
  there
  some unique identifier for a database too, so that object-id and
  db-id
  could be combined into a globally unique id?
 
 
 
 
  --
  cheers,
  Thorsten
 
  --
  UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
 
 
 

 --
 cheers,
 Thorsten

 --
 UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe



Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Alexander Burger
Hi Thorsten,

 I want to export the objects to a textual representation that might be
 edited and then committed again, so I must be able to find out which DB
 object is associated to the textual representation. 

Note that in general it is not recommended to access external objects by
their name.

It is true that you can easily write it to a file, simply with 'print',

   (print '{33})

and you can also 'read' it back again.

The problem is that {33} might meanwhile be deleted from the DB, i.e.
the block at offset 33 is returned to the free list, and reading and
accessing this object would result in a runtime error. Or, even worse,
this block may be re-used by some completely different object.

Therefore, as Henrik pointed out, portable access to database objects is
only meaningful via their index keys.


Concerning you intention to export objects to an editable
representation:

There is a 'dump' function exactly for that purpose. It writes arbitrary
Pilog selections to the current output channel.

Taking the salutations from demo 'app' as an example

: (load @lib/too.l)

: (dump (db nm +Sal @@))
   ...
   (obj ((+Sal) nm Herr)
  sex T
  hi Sehr geehrter Herr @1, )
   (obj ((+Sal) nm Herr Dr.)
  sex T
  hi Sehr geehrter Herr Dr. @1, )
   (obj ((+Sal) nm Mr.)
  sex T
  hi Dear Mr. @1, )
   (obj ((+Sal) nm Mrs.)
  sex 0
  hi Dear Mrs. @1, )
   ...

As you see, this is a format which can directly be 'load'ed.


A typical export function for a database looks like

   (de dumpMyDB ()
  (out myDB.l
 (prinl #  (stamp))
 (prinl)
 (prinl # Roles)
 (dump (db nm +Role @@))
 (println '(commit))
 (prinl)
 (prinl # User)
 (dump (db nm +User @@))
 (println '(commit))
 (prinl)
 (prinl # Shops)
 (dump (db id +Shop @@))
 (println '(commit))
 ... )
  (when (dir (tmp))
 (out myDB.tgz
(chdir (tmp)
   (in (append '(tar cfz -) @)
  (echo) ) ) ) ) )

   (de loadMyDB ()
  (when (and (info myDB.tgz) (n0 (car @)))
 (in myDB.tgz
(chdir (tmp)
   (out '(tar xfz -)
  (echo) ) ) ) )
  (load myDB.l) )

'dump' also takes care of related data blobs. In the above example, all
(the 'load'able file and the blobs) are all packed into a single TGZ
file.



 That sounds like a solution I should copy. Just out of curiosity: in a
 distributed database, the object ids ({3}, {1-2} ...) are not unique but
 might be repeated on different machines?

Right. The combination file and offset, which specifies a given
object, may appear on remote machines again. But there is no problem as
long as you use indexes to access the objects.

♪♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Alexander Burger
On Mon, Jan 27, 2014 at 09:55:28AM +0100, Alexander Burger wrote:
 'dump' also takes care of related data blobs. In the above example, all
 (the 'load'able file and the blobs) are all packed into a single TGZ
 file.

Oops, slight error! Just for the records: The TGZ file holds only the
blobs, the *.l file is separate.
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Thorsten Jolitz
Alexander Burger a...@software-lab.de writes:

Hi Alex,

 I want to export the objects to a textual representation that might be
 edited and then committed again, so I must be able to find out which DB
 object is associated to the textual representation. 

 Note that in general it is not recommended to access external objects by
 their name.

 It is true that you can easily write it to a file, simply with 'print',

(print '{33})

 and you can also 'read' it back again.

 The problem is that {33} might meanwhile be deleted from the DB, i.e.
 the block at offset 33 is returned to the free list, and reading and
 accessing this object would result in a runtime error. Or, even worse,
 this block may be re-used by some completely different object.

 Therefore, as Henrik pointed out, portable access to database objects is
 only meaningful via their index keys.

Yes, I think what Henrik uses is a good and simple solution.

 Concerning you intention to export objects to an editable
 representation:

 There is a 'dump' function exactly for that purpose. It writes arbitrary
 Pilog selections to the current output channel.

 Taking the salutations from demo 'app' as an example

 : (load @lib/too.l)

 : (dump (db nm +Sal @@))
...
(obj ((+Sal) nm Herr)
   sex T
   hi Sehr geehrter Herr @1, )
(obj ((+Sal) nm Herr Dr.)
   sex T
   hi Sehr geehrter Herr Dr. @1, )
(obj ((+Sal) nm Mr.)
   sex T
   hi Dear Mr. @1, )
(obj ((+Sal) nm Mrs.)
   sex 0
   hi Dear Mrs. @1, )
...

 As you see, this is a format which can directly be 'load'ed.

Another very useful function in PicoLisp! Although in my case I need a
special syntax for the textual representation, and I think its easier to
build that syntax by getting the info from the DB objects than to parse
and modify the dumped DB.

 A typical export function for a database looks like

(de dumpMyDB ()

(de loadMyDB ()

 'dump' also takes care of related data blobs. In the above example, all
 (the 'load'able file and the blobs) are all packed into a single TGZ
 file.

nice

 That sounds like a solution I should copy. Just out of curiosity: in a
 distributed database, the object ids ({3}, {1-2} ...) are not unique but
 might be repeated on different machines?

 Right. The combination file and offset, which specifies a given
 object, may appear on remote machines again. But there is no problem as
 long as you use indexes to access the objects.

Ok, thanks

-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Thorsten Jolitz

One more doubt:

Without going into the details, assume there is a relation like this

,
| (rel elem-id (+Number))
`

and it is reused:

1. first, it holds an (arbitrary) number that is used during object
   creation to associate it with other objects that are created too in
   the same commit. 

2. once the db-objects are, these id's can be (and are) overwritten to
   omething more meaningfull, I had my own function for this, but now I
   want to use Henriks proposal (integers produced with the id function).

Is step (1) still possible when the relation is defined as

,
| (rel elem-id (+Key +Number))
`

i.e. can I first assign e.g. 37 to it during the object creation, and
then let the 'id' function re-assign e.g. 9 to it when post-processing
the newly created objects?

-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Alexander Burger
Hi Thorsten,

 ,
 | (rel elem-id (+Number))
 `
 
 and it is reused:
 
 1. first, it holds an (arbitrary) number that is used during object
creation to associate it with other objects that are created too in
the same commit. 
 
 2. once the db-objects are, these id's can be (and are) overwritten to
omething more meaningfull, I had my own function for this, but now I
want to use Henriks proposal (integers produced with the id function).
 
 Is step (1) still possible when the relation is defined as
 
 ,
 | (rel elem-id (+Key +Number))
 `
 
 i.e. can I first assign e.g. 37 to it during the object creation, and
 then let the 'id' function re-assign e.g. 9 to it when post-processing
 the newly created objects?

Yes, sure. The object doesn't care about the meaning of that number.

But (as also Henrik pointed out), this looks very much like a +Link or
+Joint relation, doesn't it? Storing the id of some other object sounds
like a lot of maintenance work, to keep it everything consistent.


♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-27 Thread Thorsten Jolitz
Alexander Burger a...@software-lab.de writes:

Hi Alex,

 i.e. can I first assign e.g. 37 to it during the object creation, and
 then let the 'id' function re-assign e.g. 9 to it when post-processing
 the newly created objects?

 Yes, sure. The object doesn't care about the meaning of that number.

 But (as also Henrik pointed out), this looks very much like a +Link or
 +Joint relation, doesn't it? Storing the id of some other object sounds
 like a lot of maintenance work, to keep it everything consistent.

No, these numbers are already there and tell me what to link/join, so I
need them for object creation. But once the linked/joined object network
exists, can replace them with something more meaningfull like a unique
elem-ID. 

-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-26 Thread Thorsten Jolitz
Thorsten Jolitz tjol...@gmail.com
writes:

,-
| Sorry, I sent this post accidentally before I was finished, so I have to
| send it again.
`-


Hi List, 

say I want to use the internal Object ID of database object as a unique string
identifier (useful e.g. for export in a textformat), i.e. something
like:

,-
| : (put '{33} 'ID {33})
`-

how do I get the ID from a database object in a program? And is there
some unique identifier for a database too, so that object-id and db-id
could be combined into a globally unique id?


-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: How to get the Object-ID from a DB-Object?

2014-01-26 Thread Henrik Sarvell
Hi Thorsten, why do you want to do this explicitly since it's done for you
implicitly in all the various type of reference relations you have
(typically +Link)?

In Macropis I simply use the convention of having a relation called id auto
increment (by way of http://software-lab.de/doc/refG.html#genKey ) , that
way it doesn't matter which machine something is on, I will never have to
worry since something like the action /+Page/update/3/ always updates the
object of class +Page with id 3 no matter what the {x...} location might
look like.

However the impetus for this convention was actually the fact that
functions like db and collect need for instance a +Ref or +Key to be able
to fetch an object at all, having a +Key called id in all objects make
things so much easier.

But anyway, to really answer your question you might want to look into:
http://software-lab.de/doc/refI.html#id

And as far as the remote stuff goes with the db id and obj id combo AFAIK
you have to implement it yourself, you might want to start by reading this
discussion: http://comments.gmane.org/gmane.lisp.picolisp.general/2849




On Sun, Jan 26, 2014 at 6:56 PM, Thorsten Jolitz tjol...@gmail.com wrote:

 Thorsten Jolitz tjol...@gmail.com
 writes:

 ,-
 | Sorry, I sent this post accidentally before I was finished, so I have to
 | send it again.
 `-


 Hi List,

 say I want to use the internal Object ID of database object as a unique
 string
 identifier (useful e.g. for export in a textformat), i.e. something
 like:

 ,-
 | : (put '{33} 'ID {33})
 `-

 how do I get the ID from a database object in a program? And is there
 some unique identifier for a database too, so that object-id and db-id
 could be combined into a globally unique id?


 --
 cheers,
 Thorsten

 --
 UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe