I have a problem that I can't solve with better-sqlite3 on node.js
I have a table looking somewhat like this:
image of table
How can I change each rows xp, that has a level of 3 to 100? So in this example it should change id's 1 and 4 xp value to 100.
Any help is appreciated!
This is a pretty basic SQL Query, you're just needing to do a WHERE on all levels that equal 3.
UPDATE tableName
SET level = 100
WHERE level = 3
Looking at the better-sqlite3 documentation, to do an UPDATE you simply need to call the function using run()
const stmt = db.prepare('UPDATE tableName SET level = ? WHERE level = ?');
const info = stmt.run(3, 100);
Related
I have been looking for some information on counters and it seems like there is some rather contradicting info regarding to what you can do with them.
According to the official DataStax Documentation (https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/counter_type.html) "You cannot set the value of a counter, which supports two operations: increment and decrement.".
However, if we look into the BATCH CQL documentation (https://docs.datastax.com/en/dse/6.0/cql/cql/cql_reference/cql_commands/cqlBatch.html#cqlBatch__batch-updates), the bottom page example includes setting, adding, and subtracting a counter variable within a batch.
This example is likely also breaking the rule that having a counter in a table should only have counters for the rest of the table.
So what really are the limitations / usability for counters in cassandra DataStax? There does not seem to be a clear definition.
I think it's just a misunderstanding. Those pages do not contradict each other.
The CQL Counter type page correctly states that it is not possible to set the value of a counter column. For example, this is NOT valid:
UPDATE ks.counter_table
SET count = 10
WHERE pk = ?
The only valid operations on a counter column are increment and decrement. Here are some examples:
UPDATE ks.counter_table
SET count = count + 1
WHERE pk = ?
UPDATE ks.counter_table
SET count = count - 1
WHERE pk = ?
In the BATCH command page, the first 2 examples are increment operations:
UPDATE cycling.popular_count
SET popularity = popularity + 1
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
UPDATE cycling.popular_count
SET popularity = popularity + 125
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
The last example is a decrement operation:
UPDATE cycling.popular_count
SET popularity = popularity - 64
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
I can't see how the examples would break the rule about only having counters in a counter table. From the examples, I would infer that the table schema is:
CREATE TABLE cycling.popular_count
id uuid,
popularity counter,
PRIMARY KEY(id)
)
You can have as many non-counter columns in the table as long as they are part of the PRIMARY KEY.
As a side note, it is not correct to refer to the software as either "Cassandra DataStax" or "DataStax Cassandra" so I've updated the title accordingly. DataStax (the company) does not own Cassandra. The more appropriate reference is "Apache Cassandra" or just plain "Cassandra". Cheers!
I want to do a select query in Cosmos DB that returns a maximum number of results (say 50) and then gives me the continuation token so I can continue the search where I left off.
Now let's say my query has 2 equality conditions in my where clause, e.g.
where prop1 = "a" and prop2 = "w" and prop3 = "g"
In the results that are returned, I want the records that satisfy prop1 = "a" to appear first, followed by the results that have prop2 = "w" followed by the ones with prop3 = "g".
Why do I need it? Because while I could just get all the data to my application and sort it there, I can't pull all records obviously as that would mean pulling in too much data. So if I can't order it this way in cosmos itself, in the results that I get, I might only have those records that don't have prop1 = "a" at all. Now I could keep retrying this till I get the ones with prop1 = "a" (I need this because I want to show the results with prop1 = "a" as the first set of results to the user) but I might have to pull like a 100 times to get the first record since I have a huge dataset sitting in my Cosmos DB.
How can I handle this scenario in Cosmos? Thanks!
So if I am understanding your question correctly, you want to accomplish this:
SELECT * FROM c
WHERE
c.prop1 = 'a'
AND
c.prop2 = 'b'
AND
c.prop3 = 'c'
ORDER BY
c.prop1, c.prop2, c.prop3
OFFSET 0 LIMIT 25
Now, luckily you can now do this in CosmosDB SQL. But, there is a caveat. You have to set up a composite index in your collection to allow for this.
So, for this collection, my composite index would look like this:
Now, if I wanted to change it to this:
SELECT * FROM c
WHERE
c.prop1 = 'a'
AND
c.prop2 = 'b'
AND
c.prop3 = 'c'
ORDER BY
c.prop1 DESC, c.prop2, c.prop3
OFFSET 0 LIMIT 25
I could add another composite index to cover that use-case. You can see in your settings it's an array of arrays so you can add as many combinations as you'd like.
This should get you to where you need to be if I understood your question correctly.
I want to retrieve all documents in my MarkLogic db that have month=November and also group them by name, and get the count of records per name. I know I can get the frequency per name by using valuesBuilder with a range index on the name field, but how can I filter this result so that I only get the count of records for the month of November?
Supposedly valuesBuilder.fromIndexes().where() can do the filtering, but I don't know what to pass here and examples online seem to be sparse.
According to the API doc, the where clause takes a queryBuilder.query. With that in mind, you should be able to do something like this (not tested):
var marklogic = require('marklogic');
var vb = marklogic.valuesBuilder;
var qb = marklogic.queryBuilder;
vb
.fromIndexes()
.where(qb.value('month', 'November'))
I have a query object (SQL) with some records, the problem is that some of the records contain duplicate values. :( (I can't use DISTINCT in my SQL Query, so how to remove in my object?)
categories[1].id = 1
categories[2].id = 1
categories[3].id = 2
categories[4].id = 3
categories[5].id = 2
Now I want to get a list with 1, 2, 3
Is that possible?
I'm not quite sure why you say you can't use DISTINCT, even given the qualification you offered. It doesn't matter were a query came from (<cfquery>, <cfldap>, <cfdirectory>, built by hand) by the time it's exposed to your CFML code, it's just "a query", so you can definitely use DISTINCT on it:
<cfquery name="distinctCategories" dbtype="query">
SELECT DISTINCT id
FROM categories
</cfquery>
I've written this code to generate a collection. I've tried to filter the collection using subsonic.where but its not working. Actually the where clause will change on user input so i cannot add the where clause to the sqlquery and also the datatable will be filled with different data from the collection based on the user input. How can I acheive this. Also i want the collection to be unchanged so that i use it further to filter with another where clause. Alo the I've selected only two columns but all columns are showing up. Please help.
Dim sq As SB.SqlQuery = New SB.Select("product.prodcode as 'Product Code'").From(DB.Product.Schema)
Dim wh As SB.Where = New SB.Where()
Dim prod As DB.ProductCollection = sq.ExecuteAsCollection(Of DB.ProductCollection)()
wh.ColumnName = DB.Product.ServiceColumn.PropertyName
wh.Comparison = SubSonic.Comparison.NotEquals
wh.ParameterValue = System.Decimal.One
Dim tab As DataTable = prod.Where(wh).Filter().ToDataTable()
Me.GridControl1.DataSource = tab
What you're doing doesn't make much sense - the where needs to go onto the query, then hit the DB - that's the way it should work. If you want to filter after the fact you can use Linq's Where(), which will filter the list for you.