Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions matlab/external_storage/+external/Blob.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%{
# This table is a toy example of how to save a blob field into the external location
id: int
-----
external_blob: blob@imaging
%}

classdef Blob < dj.Manual
end
7 changes: 7 additions & 0 deletions matlab/external_storage/+external/getSchema.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function obj = getSchema
persistent schemaObject
if isempty(schemaObject)
schemaObject = dj.Schema(dj.conn, 'external', 'external');
end
obj = schemaObject;
end
74 changes: 74 additions & 0 deletions matlab/external_storage/set_up_dj_config.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
%%
% This notebook introduce how to set up the external storage path in the
% configuration variable |dj.config.|You could check the default of |dj.config|
% by:

dj.config
%%
% Now you can set up the host, user, and the password

dj.config('databaseHost', 'host_name')
dj.config('databaseUser', 'user_name')
dj.config('databasePassword', 'password')
%%
% We next would like to set up the external location. As an example, let's
% set up an external location for calcium imaging, which is named as |imaging|.

imaging_storage = struct('protocol', 'file',...
'location', '~/imaging');
dj.config('stores.imaging', imaging_storage)
%%
% Now the location has already set up. We could check the storage location
% by:

dj.config('stores.imaging')
%%
% We could save this config either locally with

dj.config.saveLocal()
%%
% Or save globally with

dj.config.saveGlobal()
%%
% Now let's create a schema and a table to test this location.

dj.createSchema
%%
% give a name to this new schema, for example |external|, and link it to
% a package named |+external|. Then inside the schema, create a table called |external.Blob|
% by

dj.new
%%
% In the file |+external/Blob.m|, we could see the definition of an external
% field to be |external_blob: blob@imaging|. |imaging| is the name of the storage
% we defined above. Now let's try insert 1 entry into this table:

insert(external.Blob, struct('id', 1, 'external_blob', rand(10)))
%%
% | |Check the table contents:

external.Blob
%%
% Now fetch the |external_blob |as usual:

fetch1(external.Blob, 'external_blob')
%%
% To the user, it feels like the field is still stored in the database,
% but actually it is in the external storage, in this case ~/imaging.
%
% If deleting the entry with |del| , the entry deleted is no longer fetchable,
% but the external files are not deleted unless you clean it up manually.

del(external.Blob)
%%
% To clean up, use the following command:

% get the schema object
schema = external.getSchema();
schema.external.table('imaging').delete(true,[])
%%
% 1st delete argument is bool for deleting from external source
%
% 2nd delete argument is a number for a delete limit (optional)
Binary file added matlab/external_storage/set_up_dj_config.mlx
Binary file not shown.