Comments (7)
The overhead is smaller than you think (if you use http2).
The connection is reused with http2 so you have only 1 connection to your server! But you are right if you have 1000 or more connections that is bad.
Solution: Use only 1 db-user in your backend server! (And therefore 1 connection)
Also why don't connect directly to surrealdb by your app / webpage / ...?
from surrealdb.js.
Thanks for your promptly reply, really appreciated :)
I've thought about using one connection only, but then I have to call the method await db.use('namespace123', 'db123')
each time before handling an API request to switch between different dbs or namespaces, as far as I've seen there is a message submission through websocket to SurrealDb to switch the Namespace and DB each time, so it doesn't seem 100% efficient.
Since I'm building a multi-tenant app some parts of the app are in common (eg. users, billing, etc..) while other are namespaced on the tenant side, hence the requirement of having the APIs to perform operations across namespaces/users on multiple incoming API requests without opening a lot of connections.
I'm not connecting directly from the frontend mainly for 3 reasons:
- Server side rendering for authenticated users
- Public facing REST API (therefore the requirement to have a middleware between the client, 3rd party code, and the DB)
- I prefer to have a middleware between the client and the DB also for flexibility purposes (monitoring, extensibility, complex authorization checks, etc...)
from surrealdb.js.
If you change ns + db yes that will not be optimal....
Would something like surrealdb/surrealdb#247 help you?
For your last point:
- monitoring -> just add a reverseproxy infront of surrealdb that can log / monitor stuff
- complex authorization checks -> I could not think of a use case that surrealdb can not handle... The permissons syntax is not well documented but powerfull!
from surrealdb.js.
It seems an interesting feature. Great insights for point 1 and 2, of course the documentation doesn't help a lot but by looking at the code it's seems a very promising project.
At the end I ended up creating my SDK ORM library:
https://github.com/adileo/surrealdb-ts-client
from surrealdb.js.
I think this is still an open issue. A stateless connection would be useful when deploying a Next.js app to Vercel. I'm working on a next-auth adapter for SurrealDB and it's not working on stateless cloud functions. I need just a few and very specific queries, so I'll do the fetches myself.
This ORM provides stateless connection for SurrealDB: https://github.com/StarlaneStudios/cirql
from surrealdb.js.
Hi @kearfy @tobiemh 👋 Could we reconsider this? In some scenarios its required a stateless connection to surreal from nodejs (like with next-auth on vercel nextauthjs/next-auth#6251). The current official nodejs driver only supports websockets.
A good example is cirql (https://cirql.starlane.studio/docs/guide/stateless)
from surrealdb.js.
Heya, I'm refactoring the whole socket bit of the library in #95 and also changing things up so we can have a sort-of interchangable class for WS and HTTP (the methods are different of course, so it will never be entirely the same, oh well)
Anyways, will also be adding an HTTP class in there to allow this kind of stuff
from surrealdb.js.
Related Issues (20)
- Bug: NextJS 13 (app router) with Node and Surreal HOT 2
- `TypeError: import_ws.WebSocket is not a constructor` using Vite HOT 12
- Bug: Not working with Bun? HOT 12
- Bug: Cant pass NONE value to MERGE object to unset fields HOT 1
- Feature: Safe way of using IDs in create/update statements HOT 2
- Bug: NoActiveSocket: No socket is currently connected to a SurrealDB instance. Please call the .connect() method first! HOT 8
- Bug: Not working on an IDE with Nix like Replit? HOT 2
- Bug: ErrorEvent is not defined
- Documentation: The documentation about live queries is wrong HOT 1
- Feature: Allow getting & validating signin token without authenticating token HOT 8
- Bug: type RawQueryResult doesn't allow boolean
- Bug: authenticate() can only be used with scopes. HOT 9
- Feature: Tagged Template Literals HOT 2
- Bug: Using 3rd party tokens results in "IAM error: Not enough permissions to perform this action" for create actions HOT 1
- Bug: need better error messaging HOT 2
- Feature: Temp solution for Bun websocket? HOT 7
- Feature: .open() HOT 2
- Bug: import_ws.WebSocket is not a constructor HOT 1
- Bug: HTTPStrategy doesnt seem to remain authed after 1 hour HOT 1
- Bug: Can't connect to surreal with deno HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surrealdb.js.