question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

db.create does not throw an error if a string contains '\n', it just hangs

See original GitHub issue

I’m trying to import 17652 rows from SQL Server to SurrealDB to make some tests. I wrote a small nodejs script that connects to SQL Server, reads the contents of a table and then calls db.create for each row (maybe a bulk insert method in the future? 😄)

After exactly 9360 rows, every time I tested it, the script just hangs on a db.create and never returns. I’m using the standard docker container version of SurrealDB running on Docker Desktop.

import sql from "mssql";
import Surreal from "surrealdb.js";
import _ from "lodash";

async function main() {
    const db = new Surreal("http://localhost:8000/rpc");

    const config = {
        server: "###",
        user: "###",
        password: "###",
        database: "###",
        options: {
            encrypt: false,
        },
    };

    console.log("Connecting to SQL Server...");
    await sql.connect(config);

    console.log("Connecting to SurrealDB...");
    await db.signin({
        user: "###",
        pass: "###",
    });
    await db.use("test", "test");

    console.log("Reading rows from the Table...");
    const result = await sql.query`SELECT * FROM <tableName>`;

    for (const row of result.recordset) {
        await db.create(
            "item:" + row.Id,
            row
        );
    }
    await sql.close();
    db.close();

    console.log("DONE!");
}

main();

The script is pretty simple as shown above. After it hangs, selecting from SurrealDB shows that exactly 9360 rows where created, on a total of 17652 to be created.

SELECT count() FROM task GROUP BY ALL;
[
	{
		"time": "107.4225ms",
		"status": "OK",
		"result": [
			{
				"count": 9360
			}
		]
	}
]

Am I doing something wrong?

Thanks!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tobiemhcommented, Sep 17, 2022

Hi @LeoDog896 , @Balrog994 , there is a fix coming to the database for this, and a new beta release coming this weekend!

It will support escaped characters like in JSON strings (\b, \n, \f, \r, \t) and unicode characters \u1234.

1reaction
tobiemhcommented, Sep 22, 2022

Absolutely @abdoufma 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple postgres select query hangs forever when string ...
I am unable to figure out why the following query fails in node.js with pg PostgreSQL client (version 8.5.1). db.query("SELECT id FROM ...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
10 Handling PL/SQL Errors
If no exception has been raised, SQLCODE returns zero and SQLERRM returns the message: ORA-0000: normal, successful completion . You can pass an...
Read more >
How to Throw Exceptions in Node.js - Rollbar
SyntaxError: these errors come from invalid code; TypeError: this occurs when you attempt to use a variable that is not a valid type;...
Read more >
Better Error Handling In NodeJS With Error Classes
This article is for JavaScript and NodeJS developers who want to improve error-handling in their applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found