diff --git a/src/index.js b/src/index.js
index 0dc3fdd..ec8ac02 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,9 +3,10 @@ import ReactDOM from 'react-dom';
import { Fetch } from './fetch.js';
import { ProvideDB, DBQueryConsole, DBQueryBar, DBTypeEnum, DBSourceEnum } from './database.js';
import { PhotoView, PhotoThumbView, PhotoTableLine } from './media.js';
-import { do_image_query, image_query_with_where, user_query_from_search_string } from './queries.js';
+import { do_image_query, image_query_with_where, user_query_from_search_string, maybe_image_query } from './queries.js';
import './index.css';
+import { thisExpression } from '@babel/types';
const URLLoading = ({ url }) =>
Loading: {url}
;
const URLError = ({ error }) => Failed to load URL resource: {error.message}
;
@@ -34,7 +35,7 @@ export class PhotoFromDB extends React.Component {
}
componentDidMount() {
- do_image_query(image_query_with_where(""), this.props.database, "/test_photos", "/test_photos_thumbs").then(photos => {
+ do_image_query(this.props.sql_query, this.props.database, "/test_photos", "/test_photos_thumbs").then(photos => {
this.setState({ done: true, photo: photos[0] });
});
}
@@ -42,6 +43,7 @@ export class PhotoFromDB extends React.Component {
render() {
return (
<>
+ {!this.state.done && >Querying photo from DB: {this.props.sql_query}
}
{this.state.photo && }
>
);
@@ -78,70 +80,93 @@ export class ImageWhereConsole extends React.Component {
}
}
-export class StringToQueryConsole extends React.Component {
+const PhotosTable = ({ photos }) => (
+ <>
+ {
+ photos.map((value, index) => {
+ return
+ })
+ }
+ >
+)
+
+export class TestDBStringQuery extends React.Component {
state = {
string: false,
query: false,
+ sql_query: false,
+ photos: false
}
onQueryChangeHandler = str => { this.setState({ string: str }); }
onQuerySubmitHandler = () => {
- this.setState({ query: user_query_from_search_string(this.state.string) });
+ var q = user_query_from_search_string(this.state.string);
+ var sql_q = maybe_image_query(q);
+ this.setState({ query: q, sql_query: sql_q });
+ do_image_query(sql_q, this.props.db, "/test_photos", "/test_photos_thumbs").then(photos => {
+ console.log(photos);
+ this.setState({ done: true, photos: photos });
+ });
}
render() {
+
return (
<>
+ { this.state.photos && Found {this.state.photos.length} photos.
}
+ { this.state.photos && }
>
);
}
}
-const TestDBFetch = ({ sqlite_file }) => (
-
- {({ loading, error, done, db }) => (
+const TestDBFetch = ({ db }) => (
<>
- {loading && }
- {error && }
- {done && }
DB Query Console
- {done && }
+
Example photo from DB
- {done && }
+
DB WHERE clause image search
- {done && }
+
>
- )}
-
)
-const TestDBPlayground = ({ db_name }) => (
-
- {({ loading, error, done, db }) => (
+const TestDBPlayground = ({ db }) => (
<>
- {error && }
- {done && }
+
>
- )}
-
)
ReactDOM.render(
<>
Test file fetching:
- IndexedDB playground:
-
- Test DB fetching:
-
- Test query parsing:
-
+
+ {({ loading, error, done, db }) => (
+
+ <>
+ {loading && }
+ {error && }
+ {done && (
+ <>
+
+ IndexedDB playground:
+
+ Test DB fetching:
+
+ Test queries:
+
+ >
+ )
+ }
+ >
+ )}
+
>,
document.getElementById('root')
);
diff --git a/src/queries.js b/src/queries.js
index 5082e7b..8a1c8dd 100644
--- a/src/queries.js
+++ b/src/queries.js
@@ -9,9 +9,9 @@ export function do_image_query(query, database, collection_path, collection_thum
var photos = [];
if (res && Array.isArray(res)) {
res.forEach(row => {
- var imagepath = process.env.PUBLIC_URL + collection_path + "/" + res[0]["relativePath"] + "/" + res[0]["name"];
- var thumbpath = process.env.PUBLIC_URL + collection_thumbs_path + "/" + res[0]["uniqueHash"] + ".jpg";
- photos.push(create_photo(res[0]["id"], res[0]["name"], imagepath, thumbpath));
+ var imagepath = process.env.PUBLIC_URL + collection_path + "/" + row["relativePath"] + "/" + row["name"];
+ var thumbpath = process.env.PUBLIC_URL + collection_thumbs_path + "/" + row["uniqueHash"] + ".jpg";
+ photos.push(create_photo(row["id"], row["name"], imagepath, thumbpath));
});
}
resolve(photos);
@@ -54,7 +54,7 @@ export class ConstFilter extends ResultFilter {
function match_column_name(result_type, match_against) {
if(match_against == MatchAgainstEnum.MATCH_IMAGE_NAME) {
- return "Image.name";
+ return "Images.name";
}
if(match_against == MatchAgainstEnum.MATCH_ALBUM_NAME) {
return "Album.name";
@@ -103,7 +103,7 @@ export class MatchingFilter extends ResultFilter {
throw new Error('Unsupported match type: ' + this.match_type);
}
- return "(" + (this.negate ? "NOT " : "") + match_against_str + "\"" + match_type_str + "\"" + this.match_from + ")";
+ return "(" + (this.negate ? "NOT " : "") + match_against_str + match_type_str + this.match_from + ")";
}
}
@@ -153,7 +153,7 @@ export function maybe_image_query(user_query) {
function filter_from_text_segment(result_type, segment) {
return new MatchingFilter(result_type, MatchAgainstEnum.MATCH_RESULT_NAME,
- segment['text'], MatchTypeEnum.MATCH_EQUALS, segment['negated']);
+ "\"" + segment['text'] + "\"", MatchTypeEnum.MATCH_EQUALS, segment['negated']);
}
export function user_query_from_search_string(search_string) {
@@ -176,4 +176,6 @@ export function user_query_from_search_string(search_string) {
console.log(search_string);
console.log(r);
console.log(maybe_image_query(r));
+
+ return r;
}
\ No newline at end of file