orientdb, how insert document field - nosql

I can try to insert into users class ( aka like a table) via shell a structure like this:
email: 'test#domain.com'
display_name: 'name surname test'
tags: {id: 1, name: 'first', type:'something'}
so some fields when one of them is a document.
I try this query:
insert into users (email, display_name, tags) values
('test#domain.com',
'name surname test',
{'id': 1, 'name': 'first', 'type' : 'something'}
)
but obtain this error:
Error: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #52: Set of values is missed. Example: ('Bill', 'Stuart', 300)
Command: insert into users (email, display_name, tags) values
('test#domain.com',
'name surname test',
{'id': 1, 'name': 'first', 'type' : 'something'},
)
------------------------------------------------------------^
How can I insert this data into users class?

it's a problem of carriage return. This has been fixed works with 1.0-SNAPSHOT. To avoid to update your OrientDB distribution just remove \n.

Related

Get created object with all fields

I use DBIx::class and postgreSQL.
Imagine table 'Company'. It has fields:
id => {
data_type => 'integer',
is_auto_increment => 1,
},
name => {
data_type => 'text',
},
is_client => {
data_type => 'boolean',
default_value => 'true',
},
When I create new company passing the company name only, create method returns primery key and field I passed: id, name.
How can I get all fields with default values without additional request to DB?
In other words, I want the create method to return all fields with defaults to me.
The DBIx::Class::ResultSet create method returns a DBIx::Class::Result object which has all column values filled.
On databases that support it, DBIx::Class uses RETURNING to get back server populated column values.
See https://metacpan.org/pod/DBIx::Class::ResultSource#retrieve_on_insert how to use that feature.

Flutter how to add doc id with data

I ma just entering my data in Firestore. I need to know how can I put my doc id in data?
My simple code
_firestore.collection('Users').add({
'shopname': 'Aam Dukaan',
'number': '9232313131',
'lastupdate': '',
'sendQty': '',
'id': 'here i need doc id '
});
More explanation
From image you can see I need this document id in my data.
Do it like this:
String id = FirebaseFirestore.instance.collection('Users').doc().id;
FirebaseFirestore.instance.collection('Users').doc(id).set({
'shopname': 'Aam Dukaan',
'number': '9232313131',
'lastupdate': '',
'sendQty': '',
'id': id,
});
You can get the ID before you create the new document with add and use set instead of add:
final document = _firestore.collection('Users').doc();
_firestore.collection('Users').doc(document.id).set({
'shopname': 'Aam Dukaan',
'number': '9232313131',
'lastupdate': '',
'sendQty': '',
'id': 'here i need doc id '
});
You can add a document with desired id.
final usersRef = FirebaseFirestore.instance.collection("Users");
String id = "123";
usersRef.doc(id).set(
{
"name":"somename" ,
"id":"$id",
}

How to use ARRAY of INET in flask-sqlalchemy?

I have a user model with array of ips field in my flask application. I want to use postgresql array of inet type:
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.dialects.postgresql import ARRAY, INET, Integer, Unicode, Column
db = SQLAlchemy()
class User(db.Model):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
login = Column(Unicode(15))
password = Column(Unicode(34))
name = Column(Unicode(100))
permitted_ips = Column(ARRAY(INET))
But when i make query i get bad answer:
user = User.query.get(84)
print user.permitted_ips
#['{', '1', '7', '2', '.', '2', '0', '.', '2', '5', '.', '2', ',', '1', '7', '2', '.', '2', '0', '.', '2', '5', '.', '3', '}']
instead of ['172.20.25.2', '172.20.25.3']. Current version of sqlalchemy is 0.9.10. I tried the latest one but result was the same. Is it possible to fix that?
I found that Arrays are not parsed automatically so you need to create a generic type caster with psycopg2 library.
# needed imports
from psycopg2 import STRING
from psycopg2.extensions import register_type, new_array_type
Registering the array type, it will be done one time.
# to see the oid of inet. As pointed out by #univerio the oid should never
# change, so you don't need to fetch it every time your app starts.
tp = db.engine.execute("select typarray from pg_type where typname = 'inet'")
print(tp.fetchone())
# (1041,)
# registering the array type
register_type(new_array_type((1041,), 'INET[]', STRING))
Now you can fetch the array and it will be parsed properly.
# fetch data
ips = db.engine.execute("select permitted_ips from users where id = 1")
print(ips.fetchone()[0])
# ['172.20.25.2', '172.20.25.3'].

Getting Error While Creating Text Index in MongoDB

db.inventory.createIndex(
{'category.name': 'text',
'brand.name': 'text',
'name': 'text',
'store.name': 'text',
'collection_1' : 'text',
'sku' : 'text',
'parent_sku' : 'text'
})
While Using This Commands getting error like "exception: namespace name generated from index name"
I'm using this because I M creating full Text Index in my application..
I have required many fields for Search index..
Then What should i have to do...????
You usually get this error when the auto generated index name is too long. The index name is generated by concatenating the different column names, however, the length is limited to 125 characters according to the documentation. You can resolve this error by manually specifying a shorter index name when creating the index:
db.inventory.createIndex({
'category.name': 'text',
'brand.name': 'text',
'name': 'text',
'store.name': 'text',
'collection_1': 'text',
'sku': 'text',
'parent_sku': 'text'
},
{
name: "myIndex1"
}
)

Extjs - autocomplete filter 2 properties

By following this example http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/form/forum-search.html
I could apply the auto-complete feature on my combo box, using php/postgresql query retrieves the names then:
{
xtype: 'combo',
store: ds,
hideTrigger:true,
typeAhead: false,
id: 'search_input_text',
width: 187,
queryMode: 'remote',
hideLabel: true,
queryParam: 'query',
displayField: 'first_name',
valueField: 'first_name',
listConfig: {
loadingText: 'Loading...',
getInnerTpl: function() {
return '{first_name}';
}}
listeners: {
buffer: 50,
change: function() {
var store = this.store;
store.clearFilter();
store.filter({
property: 'first_name',
anyMatch: true,
value : this.getValue()
});
}
}
}
Now, I need to edit this to let user enter either the first or last name of the student, and then each name entered (first or last) will be shown in the combo box.
So, I edited the query to make it retrieve the names :
SELECT first_name, last_name FROM students WHERE first_name ILIKE '%$query%' OR last_name ILIKE '%$query%' ";
and:
displayField: 'first_name'+'last_name',
valueField: 'first_name'+'last_name',
return '{first_name}'+'{last_name}';
store.filter({
property: 'first_name',
anyMatch: true,
value : this.getValue()
},
{
property: 'last_name',
anyMatch: true,
value : this.getValue()
}
but still, it retrieves only first names according to what user types,
Note that if I use this alone:
store.filter({
property: 'last_name',
anyMatch: true,
value : this.getValue()
});
it works fine with last names only.
You can apply multiple filters to data store like this:
var filters = [
new Ext.util.Filter({
filterFn: function(item){return item.get('first_name') == this.getValue() || item.get('last_name') == this.getValue();
}
})
];
store.filter(filters);
The above code block is just an idea on how to apply multiple filters in the same field. Notice the double-pipe "||". You can use "&&" as per your needs. It is like SQL query.