Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] TypeScript API Bugs and Proposed Solutions #1131 #1140

Merged
merged 14 commits into from
Jul 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/agdb_api_typescript.yaml
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
- run: npm run lint:check

agdb_api_typescript_coverage:
runs-on: ubuntu-latest
2 changes: 1 addition & 1 deletion .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ jobs:
- run: |
cd examples/server_client_typescript
npm ci
npm run lint
npm run lint:check
agdb_examples_build:
runs-on: ubuntu-latest
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@
</p>

<p align="center">
<picture><img width="25" src="./agdb_web/public/images/rust.png" alt="rust"></picture>
<picture><img width="25" src="./agdb_web/public/images/ts.png" alt="ts"></picture>
<picture><img width="25" src="./agdb_web/public/images/js.png" alt="js"></picture>
<picture><a href="./docs/guides/rust.md"><img width="25" src="./agdb_web/public/images/rust.png" alt="rust"></a>
<picture><a href="./docs/guides/typescript.md"><img width="25" src="./agdb_web/public/images/ts.png" alt="ts"></a>
<picture><a href="./docs/guides/typescript.md"><img width="25" src="./agdb_web/public/images/js.png" alt="js"></a>
<picture><img width="25" src="./agdb_web/public/images/python.png" alt="python"></picture>
<picture><img width="25" src="./agdb_web/public/images/java.png" alt="java"></picture>
<picture><img width="25" src="./agdb_web/public/images/c.png" alt="c"></picture>
@@ -55,25 +55,25 @@

The Agnesoft Graph Database (aka _agdb_) is persistent, optionally memory mapped graph database with native object 'no-text' queries. It can be used as a main persistent storage, data analytics platform as well as fast in-memory cache. Its typed schema-less data store allows for flexible and seamless data updates with no downtime or costly migrations. All queries are constructed via a builder pattern or directly as objects with no special language or text parsing.

- [Key Features](#key-features)
- [At a glance](#at-a-glance)
- [Crate Features](#crate-features)
- [Decision Tree](#decision-tree)
- [Roadmap](#roadmap)
- [Reference](#reference)
- [Key Features](#key-features)
- [At a glance](#at-a-glance)
- [Crate Features](#crate-features)
- [Decision Tree](#decision-tree)
- [Roadmap](#roadmap)
- [Reference](#reference)

## <img width="25" src="./agdb_web/static/logo.svg" alt="agdb logo">&nbsp;&nbsp;Key Features

- Data plotted on a graph
- Typed [key-value properties](docs/concepts.md#data-types) attached to graph elements (nodes & edges)
- Persistent platform agnostic file based storage (transferable between platforms)
- ACID compliant
- [Object queries](docs/queries.md) with builder pattern (no text, no query language)
- Memory mapped for fast querying
- [Server mode](docs/server.md)
- [OpenAPI clients](docs/api.md) in any programming language
- [Cloud](docs/cloud.md) hosted SaaS database
- _Db itself has no dependencies_
- Data plotted on a graph
- Typed [key-value properties](docs/concepts.md#data-types) attached to graph elements (nodes & edges)
- Persistent platform agnostic file based storage (transferable between platforms)
- ACID compliant
- [Object queries](docs/queries.md) with builder pattern (no text, no query language)
- Memory mapped for fast querying
- [Server mode](docs/server.md)
- [OpenAPI clients](docs/api.md) in any programming language
- [Cloud](docs/cloud.md) hosted SaaS database
- _Db itself has no dependencies_

## <img width="25" src="./agdb_web/static/logo.svg" alt="agdb logo">&nbsp;&nbsp;At a glance [Db]

@@ -150,7 +150,7 @@ println!("{:?}", user);
// User { db_id: Some(DbId(3)), username: "Bob" }
```

For database concepts and primitive data types see [concepts](docs/concepts.md). For comprehensive overview of all queries see the [queries](docs/queries.md) reference or continue with more in-depth [efficient agdb](docs/efficient_agdb.md).
For database concepts and primitive data types see [concepts](docs/concepts.md). For comprehensive overview of all queries see the [queries](docs/queries.md) reference or continue with more in-depth [efficient agdb](docs/guides/efficient_agdb.md).

## <img width="25" src="./agdb_web/static/logo.svg" alt="agdb logo">&nbsp;&nbsp;Crate Features

@@ -204,22 +204,24 @@ The following are planned features:

## <img width="25" src="./agdb_web/static/logo.svg" alt="agdb logo">&nbsp;&nbsp;Reference

- [API](docs/api.md)
- [API](docs/api.md)

- [But why?](docs/but_why.md)
- [But why?](docs/but_why.md)

- [Cloud](docs/cloud.md)
- [Cloud](docs/cloud.md)

- [Concepts](docs/concepts.md)
- [Concepts](docs/concepts.md)

- [Efficient agdb](docs/efficient_agdb.md)
- [Efficient agdb](docs/guides/efficient_agdb.md)

- [Performance](docs/performance.md)
- [Guides](docs/guides/)

- [Queries](docs/queries.md)
- [Performance](docs/performance.md)

- [Server](docs/server.md)
- [Queries](docs/queries.md)

- [Studio](docs/studio.md)
- [Server](docs/server.md)

- [Troubleshooting](docs/troubleshooting.md)
- [Studio](docs/studio.md)

- [Troubleshooting](docs/troubleshooting.md)
17 changes: 8 additions & 9 deletions agdb/src/query/insert_nodes_query.rs
Original file line number Diff line number Diff line change
@@ -52,8 +52,15 @@ impl QueryMut for InsertNodesQuery {
let mut result = QueryResult::default();
let mut ids = vec![];
let count = std::cmp::max(self.count, self.aliases.len() as u64);
let query_ids = match &self.ids {
QueryIds::Ids(ids) => ids
.iter()
.map(|query_id| db.db_id(query_id))
.collect::<Result<Vec<DbId>, QueryError>>()?,
QueryIds::Search(search_query) => search_query.search(db)?,
};
let values = match &self.values {
QueryValues::Single(v) => vec![v; std::cmp::max(1, count as usize)],
QueryValues::Single(v) => vec![v; std::cmp::max(query_ids.len(), count as usize)],
QueryValues::Multi(v) => v.iter().collect(),
};

@@ -67,14 +74,6 @@ impl QueryMut for InsertNodesQuery {
)));
}

let query_ids = match &self.ids {
QueryIds::Ids(ids) => ids
.iter()
.map(|query_id| db.db_id(query_id))
.collect::<Result<Vec<DbId>, QueryError>>()?,
QueryIds::Search(search_query) => search_query.search(db)?,
};

if !query_ids.is_empty() {
query_ids.iter().try_for_each(|db_id| {
if db_id.0 < 0 {
8 changes: 8 additions & 0 deletions agdb/src/query_builder/insert_nodes.rs
Original file line number Diff line number Diff line change
@@ -173,4 +173,12 @@ impl InsertNodesIds {

InsertNodesValues(self.0)
}

/// List of `key_values` to be inserted into the all nodes that are being created or
/// updated.
pub fn values_uniform<T: Into<SingleValues>>(mut self, key_values: T) -> InsertNodesValues {
self.0.values = QueryValues::Single(Into::<SingleValues>::into(key_values).0);

InsertNodesValues(self.0)
}
}
31 changes: 31 additions & 0 deletions agdb/tests/insert_nodes_test.rs
Original file line number Diff line number Diff line change
@@ -407,3 +407,34 @@ fn insert_aliases_and_normal_nodes() {
3,
);
}

#[test]
fn insert_nodes_ids_values_uniform() {
let mut db = TestDb::new();
db.exec_mut(QueryBuilder::insert().nodes().count(2).query(), 2);
db.exec_mut(
QueryBuilder::insert()
.nodes()
.ids(vec![1, 2])
.values_uniform(vec![("key", "value").into()])
.query(),
2,
);
db.exec_elements(
QueryBuilder::select().ids(vec![1, 2]).query(),
&[
DbElement {
id: DbId(1),
from: None,
to: None,
values: vec![("key", "value").into()],
},
DbElement {
id: DbId(2),
from: None,
to: None,
values: vec![("key", "value").into()],
},
],
);
}
2 changes: 1 addition & 1 deletion agdb_api/typescript/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ module.exports = {
env: {
node: true,
},
ignorePatterns: ["src/schema.d.ts"],
ignorePatterns: ["src/schema.d.ts", ".gitignore", "dist/"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest"
Loading