« first day (3852 days earlier)      last day (1318 days later) » 

06:39
hey guys, umm how do we connect javascript to a database?
I have a select tag in html, and I want the tag to change the value in the database
@d4rk4ng31 as far as I know you would need a back-end service to do that, what do you have?
@aleation Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
@aleation ASP.NET MVC (EF Core) with SQL Server 2016
*2019
but in short you basically make an XMLHttpRequest (using fetch, jQuery's ajax, or Axios library) to send the select tag value to your ASP.NET, and you change the database through ASP.NET
hmm... JS Newbie here
You wanna see the code?
<td>
	<script type="text/javascript">
		function changeState(selectedState) {

		}
	</script>
	@if (asset.State != Models.AssetState.deleted) {
		<select class="dropdown" onchange="changeState(value)">
			<option class="dropdown-item dropdown-item-text">@Html.DisplayFor(item => asset.State)</option>
			<option class="dropdown-item dropdown-item-text">
				@if (asset.State == Models.AssetState.functional)
				{
					@:under-maintenance
				}
				else if (asset.State == Models.AssetState.non_functional)
@aleation?
 
4 hours later…
10:55
If someone has ideas about database design:
0
Q: In postgres is there any real drawback on using a json field over multiple tables and one to many relationships?

paul23In our current application we are basically going to provide something called "translations" for each field. So a table would originally be like: CREATE TABLE "organisation" { id SERIAL PRIMARY, name text NOT NULL DEFAULT '', } But instead the name would now be language dependent. The basi...

11:19
@paul23 TEXT column type? 🤨
it is fine if you don't have to search in the json info
especially when trying to join. It should be an IDX column
11:37
@KarelG uh yes, what's wrong with that?
using a limited size string is actually bad for postgres
varchar(n) makes "copy" commands also really tricky where you do things like:
UPDATE table
   SET col1 = col2
11:50
you know, PostgreSQL has JSON as type
yes?
It's what the question is about, use json or use a lookup table
the origin before adding multilingual capability was a simple text field.
@paul23 this is new to me fyi
could be that they have changed its behavior
Well it has trouble when the sizes are different, i've read somewhere that in some situations string ending won't work correctly. - Not sure the actual problem
ah. TMK some engines just truncates it (when issuing that update stmt)
@KarelG yeah I'm not sure the actual problem, would have to google again for it. Just remember "this can cause trouble in some non standard but not too far fetched situations"
11:59
in its fairness, "just truncating" is actually "hiding" a problem
Problems I though were due to padding in the larger varchar, and then "size" problems when going to the smaller.
ah just went through the documentations
they have altered its behavior, TEXT is now the best yes
unless you want to have a limited information (there are use cases IMHO), character varying can be used
learned something today
12:40
@paul23 You should avoid JSON type of you can
You should use multiple tables
In extreme circumstances you should just use NoSQL
ah, he already has made his decision
13:39
o/
@nunofmendes Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
@nunofmendes Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
@nunofmendes Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
1 message moved to Trash can
I have a sequelized models and am building a controller that normalizes all these classes in order to avoid repeating code.

So basically I wanted something like:

http://pastie.org/p/1CPjgeLqWcti1x4C7bmux0

How can I achieve this?
@nunofmendes don't really understand your question
13:58
@JBis It's like trying to create abstraction because I want to create like a class Dogs extends Base<Dog> {} but already has the findall method ready
 
1 hour later…
15:27
You want to use that same method as it exists or you want to change it for the derived class?
As far as I know TS has generics right? Never used it
 
3 hours later…
18:47
JamesBot will be dead intermittently 5/6 through 5/7
2
(He's getting a new home)
 
1 hour later…
DRP
DRP
19:58
@KevinB you around?
DRP
DRP
Wanted a small clarification on promises if you may. I've got this function axios.post which has a catch. My expectation is that this axios returns a promise as per the docs. I have another async/await function that uses this initial axios function which has a try/catch. Thing is that the catch always returns undefined:

export const foo = (xyz) => {
    axios.post('http://localhost:5000/x', xyz)
    .catch(function (error) {
        if (401 === error.response.status) {return error}


Then on the other function:
debug this line: if (401 === error.response.status) {return error}
or that catch as a whole
once you have a catch... if you return undefined from it, the resulting promise is actually resolved, not rejected
DRP
DRP
I've added console logs and they do show, idea is pretty much the same as this gist: gist.github.com/fgilio/230ccd514e9381fafa51608fcf137253
Which is the same of the docs but I don't have them at hand.
but, that gist results in the error being handled, and a resolved promise being returned in the end
since an error wasn't rethrown or a rejected promise returned
DRP
DRP
20:13
I did try to rethrow let me see if I have that snip handy
for the try/catch above, api.logIn would need to re-throw any errors it encounters for the outer try/catch to receive them
hello
@King_Coda Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
Can I take a moment to comment on how absolutely toxic stackoverflow is
I asked a rather lengthy question regarding AI, as there was no way to further shorten it, and it got shut down by some mod named "chris".
unfotunately... he was probably right in doing so
it was closed by 3 people
Ok, so, your question... what exactly is... the question
> The challenge is that I have to code the solution in either of these two languages. As I am inexperienced in these, I require assistance.
you provided two code snippets of your own, one in ruby the other in python, but i don't see where you stated what the output was, or what you expected them to be,
i don't completely agree with the close reason those three users reached agreement on, but the question in it's current state is a bit unclear imo.
DRP
DRP
20:27
api.logIn is the first function... failed to mask that. The thing is that rethrowing is not working on foo so that it can be bubbled to api.logIn catch, and if I throw in api.logIn I'm still not able to capture the error from the axios
Can you expand on that function a bit? the example you gave has no return value and the catch appears incomplete
DRP
DRP
sure
@DRP Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
1 message moved to Trash can
DRP
DRP
api/index.js

export const logIn = (credentials) => {
    axios.post('http://localhost:5000/signin', credentials)
    .catch(function (error) {
        if (401 === error.response.status) {
          // The request was made and the server responded with a status code
          // that falls out of the range of 2xx
          console.log(error.response.data);
          console.log(error.response.headers);
          return error; // this is the initial way I tried
        } else if (error.request) {
actions/account.js

export const logIn = async (credentials) => {

     try{
        const res = await api.logIn(credentials);
        document.cookie= `token=${res.data.token}`;
        console.log('actions.account.logIn ->',res);
    }
    catch (err) {
        console.log('err ->',err);   // undefined , this is the part that has my head scratching, as I would expected to be at least something i.e Promise, object
        return 'ERROR:Unable to process your request.';
    }
add a return here: axios.post('ht...
what's odd to me is that you reached the catch at all there
i guess it bubbled up anyway, just without what you rethrew/returned
without the return, const res = await api.logIn(credentials); res would always be undefined
which would then cause an error in the following line
DRP
DRP
20:45
that does the job, although a bit different then what I expected, I'll have to revisit some basics. So yeah by doing that return on the axios , it is returned solved in the:

console.log('actions.account.logIn ->',res);
Thanks a lot @KevinB you are indeed The Oracle

« first day (3852 days earlier)      last day (1318 days later) »