Giter Club home page Giter Club logo

Comments (5)

fokklz avatar fokklz commented on June 8, 2024 1

Sure, thats just the current execution context for that query, like $parent inside a sub-query.

https://surrealdb.com/docs/surrealdb/surrealql/parameters#parent-this

Don't forget to close the issue ^^

from surrealdb.

kearfy avatar kearfy commented on June 8, 2024

Heya! If I understand your example correctly, you want to ensure that the column with the name of the column being contained in the $column variables, which is a string, contains a value that you pass from the client in the $value parameter? You would do this like so:

LET $column = "name";
LET $value = "biryani";

SELECT * FROM menu_item WHERE  string::startsWith($this[column], $value) LIMIT 10 FETCH categories

from surrealdb.

ahmedali5530 avatar ahmedali5530 commented on June 8, 2024

$column and $value are dynamic, so i don't really know whats coming in them.
Since i am using JavaScript I would do the above like this.

LET $column = "${column}";
LET $value = "${value}";

this is same as i am sending values directly in query.

My question is why can't i use parameters inside the query. The query works when i don't use string functions. But with string functions it gives error.

I have a similar issue for RELATE query, where i am sending extra data with parameters and they are also not working. While sending them directly in query working

from surrealdb.

fokklz avatar fokklz commented on June 8, 2024
import { Surreal } from 'surrealdb.node';

const db = new Surreal();

async function main() {
  await db.connect('ws://127.0.0.1:8000');
  await db.signin({
    username: 'root',
    password: 'root',
  });
  await db.use({ ns: 'test', db: 'test' });

  await db.create('menu_item', { name: 'Pizza' });
  let res = await db.query(
    'SELECT * FROM menu_item WHERE string::startsWith($this[$column], $value)',
    { column: 'name', value: 'P' }
  );
  console.log(res);
}

main();

i've tried around a bit, this seems to work, you where just missing the $this like @kearfy mentioned

from surrealdb.

ahmedali5530 avatar ahmedali5530 commented on June 8, 2024

This resolved the issue but can you tell me why $this is used with $column variable and why not with $value?
@fokklz

from surrealdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.